C#代码4种方法:
第一种:获得CheckBox的选中值
string save_cblJL = "";
for (int i = 0; i < this.cblJL.Items.Count; i++)
{
if (this.cblJL.Items[i].Selected == true)
{
save_cblJL += this.cblJL.Items[i].Value + ",";
}
}
第二种:获得CheckBox的选中值
string str_Save_cblJL = "";
foreach (ListItem li in cblJL.Items)
{
if (li.Selected == true)
{
str_Save_cblJL += li.Value + ",";
}
}
第三种:给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;
}