【发布时间】:2015-07-14 03:23:46
【问题描述】:
如果文本框值为空,我正在尝试禁用文本框,但我不知道我在哪里做错了以下不起作用,请检查并分享您的建议。
网络表单:
<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>
代码隐藏:
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为空,那么e.Row.Cells[i].Text.ToString()必须抛出异常 -
或
e.Row.Cells[i].Text可能包含"null"作为字符串 -
M.NasserJavaid,我没有任何 nullpointerException
标签: c# asp.net gridview textbox