1.前台的多选控件 <asp:CheckBoxList runat="server" ID="cblStr" RepeatDirection="Horizontal" > </asp:CheckBoxList>
2.后台获取多选的值
string str= string.Empty;
foreach (ListItem li in cblStr.Items)
{
if (li.Selected == true)
{
str+= li.Value + ",";
}
}
str.TrimEnd(','); 就是你需要的多选值
第三种:给CheckBoxList赋值
foreach (string str in split)
{
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Text == str)
{
CheckBoxList1.Items[i].Selected = true;
}
}
}
第四种:判断是否选中
var flag1=0;
var checkobj = document.getElementById("CheckBoxList1");
var checks = checkobj.getElementsByTagName("input");
for(var n=0;n<checks.length;n++)
{
if(checks[n].type=="checkbox" && checks[n].checked==true)
{
flag1=1;
}
}
if(flag1==0)
{
alert("请选择栏目设置!");
return false;
}