Check multiple items in ASP.NET CheckboxList

佐手、 提交于 2019-11-30 13:40:45
Muhammad Akhtar

The best technique that will work for you is the following:

chkApplications.Items.FindByValue("2").Selected = true;
chkApplications.Items.FindByValue("6").Selected = true;

OR you can simply do it like...

  foreach (ListItem item in chkApplications.Items)
    {
        if (item.Value == "2" || item.Value == "6")
        {
            item.Selected = true;
        }
    }
foreach (var item in cb.Items.Cast<ListItem>()
        .Where (li => li.Value == "2" || li.Value == "6"))
   item.Selected = true;
Sara

you can put the value in a list (MyList), and use FindByValue to check them.

foreach (var item in MyList)
{
    checkBoxList.Items.FindByValue(item.id).Selected = true;
}

Instead of trying to select the item through chkApplications.SelectedValue try chkApplications.Items.Item(2).Selected = True chkApplications.Items.Item(6).Selected = True

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!