Textbox values retrieving null in code behind asp.net c#? -


i have griview contains itemtemplates i'm not able retrieve values in code behind. i'm getting null value in textbox. here aspx code:

<asp:gridview runat="server" id="gridview" autogeneratecolumns="false" width="1100px" cellpadding="4" forecolor="#333333" gridlines="none" height="600px" >     <alternatingrowstyle backcolor="white" />     <columns>         <asp:templatefield headertext="refine requirement " headerstyle-width="200px">             <itemtemplate>                 <asp:textbox id="textbox1" runat="server" forecolor="black" height="27px" width="200px" font-size="medium"></asp:textbox>             </itemtemplate>             <headerstyle width="200px" />         </asp:templatefield>         <asp:templatefield headertext="reason">             <itemtemplate>                 <asp:textbox id="reason" textmode="multiline" forecolor="black" font-size="medium" runat="server"></asp:textbox>             </itemtemplate>         </asp:templatefield>     </columns>  </asp:gridview>  <asp:button id="buttoninsert"  runat="server" forecolor="white" bordercolor="white" onclick="get" borderstyle="double" backcolor="#990000"  text="submit requirements" style="position:relative; left:400px;" /> 

and here code behind :

public void get(object o,eventargs e) { foreach (gridviewrow gvr in gridview.rows) {     textbox txtamount = gvr.findcontrol("textbox1") textbox;     string s = txtamount.text; } } 

but i'm getting null value in s.

if using function retrieving grid view database , calling in page_load() event may cause issue. try call function in page_loadcomplete() event , work.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -