现在我有一个CheckBoxList 包括“1”,“2”,“3” 这三个选项,还有一个CheckBox1  Text = "4" ,
我想实现: 当选择“1”选项时,“3” 和 “4”被禁用; 当选择“2” 时,“3”被禁用;
并且 得实现 反选 后被禁用的选项还原成 Enabled = true 的状态!!为什么我这样写,会出现问题: 当选择 选项“1”的时候 "3" 没被禁用。 啥问题?求大家帮忙!
(小弟真脑残了-_-!) <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;
            }
        }
    }
 

解决方案 »

  1.   

    this.CheckBoxList1.Items[2].Enabled = his.CheckBox1.Enabled = !this.CheckBoxList1.Items[2].selected
    this.CheckBoxList1.Items[3].Enabled=!this.CheckBoxList1.Items[2].selected
      

  2.   


    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;
            }
      

  3.   

    symbol441
    Thank U Very Very Much!