asp.net - How to find Null values from Gridview Textbox [C#] -


i trying disable textbox if textbox value null, don`t know doing wrong following not working, kindly check , share suggestion.

webform:

        <asp:gridview id="gridview1" runat="server" autogeneratecolumns="false"              onrowdatabound="gridview1_rowdatabound">             <columns>                 <asp:templatefield headertext="group">                     <itemtemplate>                         <asp:textbox id="textbox2" commandargument="now_cmd" runat="server"              value='<%# eval("now") %>'></asp:textbox> <cc1:calendarextender id="calendarextender1" runat="server" targetcontrolid="textbox2"></cc1:calendarextender>                     </itemtemplate>                 </asp:templatefield>                 <asp:templatefield headertext="activity">                     <itemtemplate>                         <asp:textbox id="textbox3" commandargument="after_cmd" value='<%# eval("afteronehour") %>' runat="server"              ></asp:textbox>             <cc1:calendarextender id="calendarextender2" runat="server" targetcontrolid="textbox3"></cc1:calendarextender>                      </itemtemplate>                 </asp:templatefield>             </columns>         </asp:gridview> 

codebehind:

protected void gridview1_rowdatabound(object sender, gridviewroweventargs e) {     if (e.row.rowtype == datacontrolrowtype.datarow)     {         (int = 0; < e.row.cells.count; i++)         {             string value = e.row.cells[i].text.tostring();              if (e.row.cells[i].text.tostring() == string.empty)             {                  e.row.cells[i].enabled = false;             }         }     } } 

my input:

2015-07-03 09:44:02.380     2015-07-04 09:44:02.380 2015-07-03 09:4`4:53.360    2015-07-04 09:44:53.360 2015-07-03 09:47:00.580     null 2015-07-03 09:47:00.580     2015-07-04 09:44:53.360 

so need disable check box null values

you binding textbox datasource columns not cell should looking text in textbox not cell. may use findcontrol instead of looping through gridview row.

protected void gridview1_rowdatabound(object sender, gridviewroweventargs e) {        if (e.row.rowtype == datacontrolrowtype.datarow)    {       textbox tb1= (textbox)e.row.findcontrol("textbox2");      if(string.isnullorempty(convert.tostring(databinder.eval(e.row.dataitem, "now"))))          tb1.enabled = false;         textbox tb2= (textbox)e.row.findcontrol("textbox3");       if(string.isnullorempty(convert.tostring(databinder.eval(e.row.dataitem, "afteronehour"))))          tb2.enabled = false;     } } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -