asp.net - Why do I get empty strings when reading GridViewRow text values? -


well since no 1 able determine why my datatable not updated gridview data, i'm trying directly values gridview.

problem text values reading gridviewrows empty strings.

here code:

aspx markup code gridview:  <asp:gridview id="esbandtsrvaluesinputgridview" runat="server" showfooter="true" autogeneratecolumns="false">     <columns>     <asp:boundfield datafield="awardid" headertext="award id" visible="false" />     <asp:boundfield datafield="awardname" headertext="award name" />     <asp:templatefield headertext="esbvalue">         <itemtemplate>             <asp:textbox id="esbvalue" text='<%# eval("esbvalue") %>' runat="server"></asp:textbox>         </itemtemplate>     </asp:templatefield>     <asp:templatefield headertext="tsrvalue">         <itemtemplate>             <asp:textbox id="tsrvalue" text='<%# eval("tsrvalue") %>'  runat="server"></asp:textbox>         </itemtemplate>     </asp:templatefield>     </columns> </asp:gridview> 

initializing gridview data code-behind of button click:

datatable dt = new datatable(); dt.columns.add(new datacolumn("awardid", typeof(string))); dt.columns.add(new datacolumn("awardname", typeof(string))); dt.columns.add(new datacolumn("esbvalue", typeof(string))); dt.columns.add(new datacolumn("tsrvalue", typeof(string))); datarow[] pspawards = dtawards.select("awardtype = 'psp'"); foreach (datarow dr in pspawards) {     dt.rows.add(dr["awardid"].tostring(), dr["awardname"].tostring(), "0", "100"); } viewstate["esbandtsrvaluesdatatable"] = dt; esbandtsrvaluesinputgridview.datasource = dt; esbandtsrvaluesinputgridview.databind(); 

trying read gridviewrow values:

for (int rowcount = 0; rowcount < esbandtsrvaluesinputgridview.rows.count; rowcount++) {      int cell0val, cell1val, cell2val, cell3val;      //input text blank all:     //tryparse returns false (because if use parse instead, exception occurs):      int32.tryparse(esbandtsrvaluesinputgridview.rows[rowcount].cells[0].text, out cell0val);     int32.tryparse(esbandtsrvaluesinputgridview.rows[rowcount].cells[1].text, out cell1val);     int32.tryparse(esbandtsrvaluesinputgridview.rows[rowcount].cells[2].text, out cell2val);     int32.tryparse(esbandtsrvaluesinputgridview.rows[rowcount].cells[3].text, out cell3val);      int val1 = int32.parse(esbandtsrvaluesinputgridview.rows[rowcount].cells[0].text);     int val2 = int32.parse(dr["awardid"].tostring());      if (val1 == val2)     {         rowindex = rowcount;         break;     } } 

so how can actual text values when reading gridviewrows ?

i need values of boundfields textfields ..

and i'm using visual studio 2005 .net 2.0 framework ..

replace last cod block this

you can not directly value textbox ..you have find control id

gridview

<asp:gridview id="esbandtsrvaluesinputgridview" runat="server" showfooter="true"     autogeneratecolumns="false">     <columns>         <asp:templatefield headertext="award name">             <itemtemplate>                 <asp:label id="lblawardid"  runat="server" text='<%# eval("awardid") %>' style="display: none;"></asp:label>                 <asp:label id="lblawardname"  runat="server" text='<%# eval("awardname") %>'></asp:label>             </itemtemplate>         </asp:templatefield>         <asp:templatefield headertext="esbvalue">             <itemtemplate>                 <asp:textbox id="esbvalue" text='<%# eval("esbvalue") %>' runat="server"></asp:textbox>             </itemtemplate>         </asp:templatefield>         <asp:templatefield headertext="tsrvalue">             <itemtemplate>                 <asp:textbox id="tsrvalue" text='<%# eval("tsrvalue") %>' runat="server"></asp:textbox>             </itemtemplate>         </asp:templatefield>     </columns> </asp:gridview> 

get values

 (int rowcount = 0; rowcount < esbandtsrvaluesinputgridview.rows.count; rowcount++)         {              int cell0val, cell1val, cell2val, cell3val;              //input text blank all:             //tryparse returns false (because if use parse instead, exception occurs):              int32.tryparse(((label)esbandtsrvaluesinputgridview.rows[rowcount].findcontrol("lblawardid")).text, out cell0val);             int32.tryparse(((label)esbandtsrvaluesinputgridview.rows[rowcount].findcontrol("lblawardname")).text, out cell1val);             int32.tryparse(((textbox)esbandtsrvaluesinputgridview.rows[rowcount].findcontrol("esbvalue")).text, out cell2val);             int32.tryparse(((textbox)esbandtsrvaluesinputgridview.rows[rowcount].findcontrol("tsrvalue")).text, out cell3val);             int32.tryparse(esbandtsrvaluesinputgridview.rows[rowcount].cells[3].text, out cell3val);              int val1 = int32.parse(esbandtsrvaluesinputgridview.rows[rowcount].cells[0].text);             int val2 = int32.parse(dr["awardid"].tostring());              if (val1 == val2)             {                 rowindex = rowcount;                 break;             }         } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -