如何实现checkboxlist某一项选中后,checkboxlist其他选项取消选择。不选这个选项时,其他选项仍可复选。

2024-12-01 10:18:22
推荐回答(1个)
回答(1):

前台:

1
2
3
4
5


后台:
protected void Page_Load(object sender, EventArgs e)
{
CheckBoxList1.SelectedIndexChanged += new EventHandler(CheckBoxList1_SelectedIndexChanged);
}
void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (CheckBoxList1.Items[0].Selected)
{
for (int i = 1; i < CheckBoxList1.Items.Count; i++)
{
CheckBoxList1.Items[i].Enabled = false;
}
}
else
{
for (int i = 1; i < CheckBoxList1.Items.Count; i++)
{
CheckBoxList1.Items[i].Enabled = true;
}
}
}