c# - 如果启用了另一个复选框,如何禁用一个复选框?
问题描述
我的网页有两个复选框,我想要的是:
- 最初,两个复选框都未选中。
- 如果 Checkbox1 被选中,Checkbox2 应该被禁用。
- 如果 Checkbox2 再次未选中,Checkbox2 应该再次启用。
- 反之亦然。
请帮助我修改我的代码。
这是我的代码:
protected void CheckBox1_CheckedChanged1(object sender, EventArgs e)
{
//this.CheckBox1.CheckedChanged += new System.EventHandler(CheckBox1_CheckedChanged1);
if (CheckBox1.Checked)
CheckBox2.Enabled = false;
}
protected void CheckBox2_CheckedChanged2(object sender, EventArgs e)
{
if (CheckBox2.Checked)
CheckBox1.Enabled = false;
}
HTML
<asp:CheckBox ID="CheckBox1" runat="server" Height="33px" OnCheckedChanged="CheckBox1_CheckedChanged1" Font-Bold="True" style="margin-left: 33px" Text="Remove Blank Lines" TextAlign="Left" Width="162px" />
<asp:CheckBox ID="CheckBox2" runat="server" Font-Bold="True" Height="33px" OnCheckedChanged="CheckBox2_CheckedChanged2" style="margin-left: 28px" Text="Add Prefix/ Suffix to Blank Lines" TextAlign="Left" Width="259px" />
解决方案
只需使用:
CheckBox2.Enabled = !CheckBox1.Checked;
推荐阅读
- rust - Cargo.toml:如何根据我的 crate 的特性选择依赖项的特性?
- matlab - 如何测试范围值是否包含在 MATLAB 中的任何其他范围值中?
- javascript - 如何修复参数“documentPath”的值不是有效的资源路径?
- matlab - 如何在Matlab中使矩阵中的NaN值透明
- git - 移动到 BitBucket 后无法推送到原始 git 存储库
- numpy - 计算numpy数组前缀最小数组
- c - 如何在 C 中匹配 MM/DD/YYYY 日期字符串格式
- java - 获取 [1586297427.353][严重]:从渲染器接收消息超时:自从我的 Chrome 浏览器更新到 81.0.4044.92 以来,0.100
- javascript - 使用带有 API 网关 (CORS) 的超级代理发出 GET 请求
- julia - 加快从数组重采样