How to retrieve textbox value in gridview when happen indexchanging event in asp.net? -
i have gridview bound objectdatasource. add textbox , button each row in grid allow user enter date , click button subscribe. no field exists in gridview textbox , return null refrence when run page. should do? please help.. here's aspx file , code behind:
<asp:templatefield headertext="content" itemstyle-width="150"> <itemtemplate> <asp:textbox id="name" runat="server" /> </itemtemplate> <itemstyle width="150px"></itemstyle> </asp:templatefield> <asp:buttonfield commandname="select" text="save" buttontype="button" />
code-behind:
protected void gridview1_selectedindexchanging(object sender, gridviewselecteventargs e) { gridviewrow row = gridview1.rows[e.newselectedindex]; string s = row.cells[0].text; //fetch value of name. textbox tb = (textbox)gridview1.findcontrol("name"); string name = tb.text; }
value of name null...
gridviewrow
has findcontrol
method. may try,
protected void gridview1_selectedindexchanging(object sender, gridviewselecteventargs e) { gridviewrow row = gridview1.rows[e.newselectedindex]; textbox tb = row.findcontrol("name") textbox; string name = tb.text; }
Comments
Post a Comment