
Asp.Net 判断Repeater中的checkbox是否被选中有问题!
前台代码中有个Repeater,这个Repeater中的每个常规项都有个<asp:CheckBoxID="cbChoose"runat="server"Text='<%#...
前台代码中有个Repeater,
这个Repeater中的每个常规项都有个<asp:CheckBox ID="cbChoose" runat="server" Text='<%# Eval("SId") %>' />
后台代码中我只这样找到Repeater并判断CheckBox是否被选中的:
foreach (RepeaterItem item in this.Repeater1.Items)
{
CheckBox cb = (CheckBox)item.FindControl("cbChoose");
if (cb.Checked)
{
Response.Write("<script>alert('ok');</script>");
}
}
问题:
我打断点看了,能找得到CheckBox的值,也能看见CheckBox的Text,但是不管页面上的CheckBox是否被选中,后台FindControl中的CheckBox.Check都是等于false,请问知道怎么决绝这个问题吗?
我这个CheckBox,不是CheckBoxList。 展开
这个Repeater中的每个常规项都有个<asp:CheckBox ID="cbChoose" runat="server" Text='<%# Eval("SId") %>' />
后台代码中我只这样找到Repeater并判断CheckBox是否被选中的:
foreach (RepeaterItem item in this.Repeater1.Items)
{
CheckBox cb = (CheckBox)item.FindControl("cbChoose");
if (cb.Checked)
{
Response.Write("<script>alert('ok');</script>");
}
}
问题:
我打断点看了,能找得到CheckBox的值,也能看见CheckBox的Text,但是不管页面上的CheckBox是否被选中,后台FindControl中的CheckBox.Check都是等于false,请问知道怎么决绝这个问题吗?
我这个CheckBox,不是CheckBoxList。 展开
2个回答
展开全部
关键是你这段代码在什么事件内执行的.如果在一个Button里,估计就可以获得Checked,你要是在页面加载或者数据绑定这样的事件内执行,当然不会选中.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询