asp.net - itemTemplate item id not existing in code behind -


i trying create textboxes equal number of rows in grid view (databound db). here markup

<asp:gridview id="quizgrid" runat="server" cssclass="grid" autogeneratecolumns="false">             <columns>                  <asp:boundfield datafield="admissionno" headertext="admission no"/>                  <asp:boundfield datafield="studentname" headertext="name" />                     <asp:templatefield>                         <itemtemplate>                             <asp:textbox runat="server" id="marks" > </asp:textbox>                         </itemtemplate>                     </asp:templatefield>             </columns> 

but when use marks in code behind says

quizgrid_marks_0 not exists in current context

what im doing wrong here?

you can't access textbox in code behind file, rather need find them in rowdatabound event this:-

protected void quizgrid_rowdatabound(object sender, gridviewroweventargs e)         {             if(e.row.rowtype == datacontrolrowtype.datarow)             {                 textbox marks = (textbox)e.row.findcontrol("marks");                 txtmarks.text = "test";             }         } 

edit:

okay, suppose have button btngetdata button click event btngetdata_click, can find textbox text looping through gridview rows this:-

protected void btngetdata_click(object sender, eventargs e) {     gridview quizgrid = (gridview)page.findcontrol("quizgrid");     foreach (gridviewrow row in quizgrid.rows)      {         textbox marks = (textbox)row.findcontrol("marks");     } } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -