c# - GridView row not updating, text from textbox in gridview edit template not coming -
i have grid view in want update row not happening. datasource datatable. please help.
below markup
<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> and code behind
protected void grdv_rowupdating(object sender, gridviewupdateeventargs e) { // retrieve row being edited. int index = grdv.editindex; gridviewrow row = grdv.rows[index]; textbox t1 = row.findcontrol("desctbx") textbox; datatable dt = (datatable)session["tmdatatable"]; dt.rows[index]["description"] = t1.text; //description column of datatable dt.acceptchanges(); grdv.editindex = -1; grdv.datasource = dt; grdv.databind(); } on debugging , find textbox passing empty string t1.text ="" after have filled textbox new values. think error in line
textbox t1 = row.findcontrol("desctbx") textbox; pageload 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; }
alter code bit , check. change editindex e.rowindex
protected void grdv_rowupdating(object sender, gridviewupdateeventargs e) { gridviewrow row = grdv.rows[e.rowindex]; // line changed textbox t1 = row.findcontrol("desctbx") textbox; datatable dt = (datatable)session["tmdatatable"]; dt.rows[row.dataitemindex]["description"] = t1.text; //description column of datatable dt.acceptchanges(); grdv.editindex = -1; grdv.datasource = dt; grdv.databind(); } have done this:
protected void page_load(object sender, eventargs e) { if(!ispostback) { grdv.datasource = session["tmdatatable"]; grdv.databind(); } }
Comments
Post a Comment