在codebehind asp.net检查默认的CheckBoxList项目项目、asp、codebehind、CheckBoxList

2023-09-04 10:55:48 作者:天生傲骨、怎能屈服

在我的网页我有一个的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>
 

解决方案 ASP.NET中的Code Behind技术

如果您要检查其中的一些有一定条件的,可以使用这样的:

 保护无效的Page_Load(对象发件人,EventArgs的)
{
    的for(int i = 0; I< CheckBoxList.Items.Count;我++)
    {
        如果(someCondition)
            CheckBoxList.Items [I] .Selected = TRUE;

    }

}
 

从这里

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

 
精彩推荐
图片推荐