GridView row not updating

blueacidz

New Member
I have grid view in which I want to update row but it is not happening. The datasource is a DataTable. Please help.
Below is the markup\[code\]<asp:GridView ID="GrdV" runat="server" AutoGenerateColumns="false" OnRowEditing="GrdV_RowEditing" OnRowUpdating="GrdV_RowUpdating"> <Columns> <asp:TemplateField HeaderText="Clip Description"> <ItemTemplate> <asp:Label ID="lblDescrptn" runat="server" Text='<%# Bind("Description") %>'> </asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="descTbx" runat="server" Text='<%# Bind("Description") %>'> </asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:CommandField ShowEditButton="True" /> </Columns>\[/code\]and this is code behind\[code\] protected void GrdV_RowUpdating(object sender, GridViewUpdateEventArgs e) { // Retrieve the row being edited. int index = GrdV.EditIndex; GridViewRow row = GrdV.Rows[index]; TextBox t1 = row.FindControl("descTbx") as TextBox; DataTable dt = (DataTable)Session["tmdataTable"]; dt.Rows[index]["Description"] = t1.Text; //Description is a column of my DataTable dt.AcceptChanges(); GrdV.EditIndex = -1; GrdV.DataSource = dt; GrdV.DataBind(); }\[/code\]On debugging , I find that textbox is passing empty string \[code\]t1.Text =""\[/code\] even after I have filled textbox with new values.I think the error is in line
\[code\]TextBox t1 = row.FindControl("descTbx") as TextBox;\[/code\]PageLoad code
\[code\] protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GrdV.DataSource = Session["tmdataTable"]; GrdV.DataBind(); } DataTable Finaldt = getTable(); GrdV.DataSource = Finaldt; GrdV.DataBind(); Session["tmdataTable"] = Finaldt; }\[/code\]
 
Back
Top