asp.net 中如何获取CheckBoxList的值

2024-12-16 16:35:41
推荐回答(2个)
回答1:

string Quanxian = string.Empty;
if (CheckBoxList1.SelectedIndex == -1)
{
Func.Alert("请分配地区权限", this);
return;
}
else
{
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Selected)
{
Quanxian += li.Value.ToString() + ",";
}
}
Quanxian = Quanxian.Substring(0, Quanxian.Length - 1);
}

回答2:

foreach (ListItem li in this.CheckBoxList1.Items)
{
if (li.Selected)
{
Response.Write(li.Value + ",");
Response.Write(li.Text + "
\r\n");
}
}