If one checkbox is checked, set the other to unchecked

前端 未结 9 1651
Happy的楠姐
Happy的楠姐 2021-01-13 10:06

I have two checkboxes on my form; chkBuried and chkAboveGround. I want to set it up so if one is checked, the other is unchecked. How can I

9条回答
  •  生来不讨喜
    2021-01-13 10:37

    I needed to show or not show a table when activating the CheckBox, how they were two, if I activated both, everything was fine, but if I tried to deactivate one later, the other was also deactivated. PD: The default value for the tables that I used was Visible=false. The solution I got was the following:

     protected void YourNameOfMethodForBothCheckBox(object sender, EventArgs e)
        {
            if (CheckBox_1.Checked == true)
            {
                Table_1.Visible = true;
    
                if (CheckBox_2.Checked == true)
                {
                    Table_2.Visible = true;
                }
                else { Table_2.Visible = false; }
    
    
            }
            else
            {
                Table_1.Visible = false;
    
                if (CheckBox_2.Checked == false)
                {
                    Table_2.Visible = false;
                }
                else
                {
                    Table_2.Visible = true;
    
                }
            }
    
        }
    

提交回复
热议问题