Я пытаюсь отключить текстовое поле, если значение текстового поля равно null, но я не знаю, где я делаю неправильно, следующее не работает, любезно проверяйте и делитесь своими предложение.Как найти значения Null из текстового поля Gridview [C#]
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)
{
for (int i = 0; i < 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;
}
}
}
}
Мой вход:
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
Поэтому мне нужно отключить флажок NULL значения
Есть ли 'NullPointerException' вы видели? –
Если 'e.Row.Cells [i] .Text' равно null, то' e.Row.Cells [i] .Text.ToString() 'должен вызывать исключение –
Или' e.Row.Cells [i] .Text' может содержать '' null "' как строку –