Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit Bound Columns... Need Help!!!

Status
Not open for further replies.

ballz

Programmer
May 10, 2003
2
0
0
US
Ok... here's the code guys and gals... for some reason... when the datagrid goes into edit mode, textboxes appear but once the value has changed within the textbox and update is clicked, the value doesn't get passed...

i'm trying to get the "jobnumber" value to change... it was once a bound column, but I tried template column and the value still doesn't change...

Datagrid:

<asp:DataGrid id="grdOM" runat="server" onEditCommand="DataGrid_Edit" onCancelCommand="DataGrid_Cancel" onUpdateCommand="DataGrid_Update" autogeneratecolumns="False" DataKeyField="omticketid" OnSelectedIndexChanged="grdOM_SelectedIndexChanged">
<SelectedItemStyle backcolor="Khaki"></SelectedItemStyle>
<AlternatingItemStyle backcolor="White"></AlternatingItemStyle>
<HeaderStyle font-bold="True" backcolor="Silver"></HeaderStyle>
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:BoundColumn Visible="False" DataField="omticketid" ReadOnly="True" HeaderText="ID"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Job Number">
<ItemTemplate>
<asp:Label runat="server" text='<%# DataBinder.Eval(Container, "DataItem.jobnumber") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="JobNumber" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.jobnumber") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="omticket" SortExpression="ORDER BY omticket" ReadOnly="True" HeaderText="O &amp; M Ticket"></asp:BoundColumn>
<asp:BoundColumn DataField="base" ReadOnly="True" HeaderText="Base"></asp:BoundColumn>
<asp:BoundColumn DataField="building" ReadOnly="True" HeaderText="Building"></asp:BoundColumn>
<asp:BoundColumn DataField="type" ReadOnly="True" HeaderText="Type"></asp:BoundColumn>
<asp:BoundColumn DataField="datesubmitted" ReadOnly="True" HeaderText="Submitted" DataFormatString="{0:d}"></asp:BoundColumn>
<asp:BoundColumn DataField="daterequired" ReadOnly="True" HeaderText="Required"></asp:BoundColumn>
<asp:BoundColumn DataField="status" HeaderText="Status"></asp:BoundColumn>
<asp:BoundColumn DataField="port" HeaderText="Port"></asp:BoundColumn>
<asp:BoundColumn DataField="cabinfo" HeaderText="Cabinet Info"></asp:BoundColumn>
<asp:BoundColumn DataField="notes" HeaderText="Notes"></asp:BoundColumn>
</Columns>
</asp:DataGrid>



Update Code:

public void DataGrid_Update(object source, DataGridCommandEventArgs e)
{
TextBox txtjobnumber = new TextBox();
txtjobnumber = (TextBox)e.Item.Cells[2].FindControl("JobNumber");
string jobnumberValue = txtjobnumber.Text.ToString();
int omticketidValue = Convert.ToInt32(grdOM.DataKeys[e.Item.ItemIndex]);
//string jobnumberValue = ((TextBox)e.Item.Cells[2].Controls[0]).Text.ToString();
string qStr = "UPDATE omticket SET jobnumber = '" + jobnumberValue + "' WHERE omticketid = " + omticketidValue;
using(OdbcConnection con = new OdbcConnection(ConnString))
using(OdbcCommand cmd = new OdbcCommand(qStr, con))
{

//string jobnumberValue = ((TextBox)e.Item.Cells[2].Controls[0]).Text.ToString();
//string jobnumberString2 = jobnumberValue.Text;
//string jobnumberString = "321";

//cmd.Parameters.Add(new OdbcParameter("@jobnumber", OdbcType.VarChar, 50));
//cmd.Parameters["@jobnumber"].Value = jobnumberString;
//cmd.Parameters.Add("@jobnumber", OdbcType.VarChar, 50).Value = jobnumberValue;
//cmd.Parameters.Add("@omticketid", OdbcType.Int).Value = e.Item.Cells[1].Text;
Label3.Text = jobnumberValue + " " + omticketidValue;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}

grdOM.EditItemIndex = -1; //switches datagrid out of edit mode
createSearchQuery(optPSI.SelectedValue,optMonth.SelectedValue,optYear.SelectedValue,optStatus.SelectedValue);

}
 
Have you checked to make sure it is actually entering the update function? I'm working on a datagrid right now and I used the properties window of Visual Studio to set the event handlers. It automatically added this code:

Code:
this.grid.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.grid_CancelCommand);
			this.grid.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.grid_EditCommand);
			this.grid.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.grid_UpdateCommand);

My grid doesn't even contain the onUpdateCommand property (in the HTML portion) and it's working. So make sure it is registering the event with the event handler. Let me know if this is the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top