62,041
社区成员
发帖
与我相关
我的任务
分享
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True"
onselectedindexchanged="CheckBoxList1_SelectedIndexChanged"
RepeatDirection="Horizontal">
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
</asp:CheckBoxList>
<br />
<asp:CheckBox ID="CheckBox1" runat="server" Text="4" Value="4" />
<br />
//实现 当一个checkbox选中后,禁用ChekBoxlist的 某项的。
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (ListItem item in this.CheckBoxList1.Items)
{
if (item.Selected == true)
{
if (Convert.ToInt32(item.Value) == 1)
{
this.CheckBoxList1.Items[2].Enabled = false;
this.CheckBox1.Enabled = false;
}
else if (Convert.ToInt32(item.Value) == 2)
this.CheckBoxList1.Items[2].Enabled = false;
}
else
{
if (Convert.ToInt32(item.Value) == 1)
{
this.CheckBoxList1.Items[2].Enabled = true;
this.CheckBox1.Enabled = true;
}
else if (Convert.ToInt32(item.Value) == 2)
this.CheckBoxList1.Items[2].Enabled = true;
}
}
}
if (CheckBoxList1.Items[0].Selected)
{
CheckBoxList1.Items[1].Enabled = CheckBoxList1.Items[2].Enabled = false; ;
}
else
{
CheckBoxList1.Items[1].Enabled = CheckBoxList1.Items[2].Enabled = true; ;
}
if (CheckBoxList1.Items[1].Enabled && CheckBoxList1.Items[1].Selected)
{
CheckBoxList1.Items[2].Enabled = false;
}