在codebehind asp.net检查默认的CheckBoxList项目 [英] checkboxlist items as checked by default in codebehind asp.net
本文介绍了在codebehind asp.net检查默认的CheckBoxList项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的网页我有一个的CheckBoxList
控制和我有7项就可以了。我想设置的7个项目的检查了我的的Page_Load
codebihind。
我的网页:
< ASP:的CheckBoxList ID =WeeklyCondition=服务器>
< ASP:列表项值=1>周六及LT; / ASP:列表项>
< ASP:列表项值=2>阳光< / ASP:列表项>
< ASP:列表项值=3>星期一< / ASP:列表项>
< ASP:列表项值=4>星期二< / ASP:列表项>
< ASP:列表项值=5>三及LT; / ASP:列表项>
< ASP:列表项值=6>周四< / ASP:列表项>
< ASP:列表项值=7>周五< / ASP:列表项>
< / ASP:的CheckBoxList>
解决方案
如果您要检查其中的一些有一定条件的,可以使用这样的:
保护无效的Page_Load(对象发件人,EventArgs的)
{
的for(int i = 0; I< CheckBoxList.Items.Count;我++)
{
如果(someCondition)
CheckBoxList.Items [I] .Selected = TRUE;
}
}
从<一个href="http://forums.asp.net/t/1315026.aspx?How%20can%20I%20set%20checkboxlist%20items%20as%20checked%20by%20default"相对=nofollow>这里
In my page I have a CheckBoxList
control and I have 7 items on it. I would like to set those 7 items as checked in my Page_load
codebihind.
my page:
<asp:CheckBoxList ID="WeeklyCondition" runat="server">
<asp:ListItem Value="1">Sat</asp:ListItem>
<asp:ListItem Value="2">Sun</asp:ListItem>
<asp:ListItem Value="3">Mon</asp:ListItem>
<asp:ListItem Value="4">Tue</asp:ListItem>
<asp:ListItem Value="5">Wed</asp:ListItem>
<asp:ListItem Value="6">Thu</asp:ListItem>
<asp:ListItem Value="7">Fri</asp:ListItem>
</asp:CheckBoxList>
解决方案
if you want to check some of those with some condition, you can use something like this:
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < CheckBoxList.Items.Count; i++)
{
if(someCondition)
CheckBoxList.Items[i].Selected = true;
}
}
from here
这篇关于在codebehind asp.net检查默认的CheckBoxList项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文