简体   繁体   English

如何使用复选框列表作为单选按钮

[英]how to use checkbox list as radio button

I have checkbox list, values are extacting from DB by button click. 我有复选框列表,通过单击按钮从DB提取值。 the vaues are ALL,Produc1,Product2. 这些值是ALL,Produc1,Product2。 by default all is selected if i select Product1 "ALL" checkbox should uncheck. 默认情况下,如果我选择Product1的“ ALL”复选框应取消选中,则全部选中。

<asp:CheckBoxList ID="chkProductOption" RepeatColumns="2" runat="server" 
                    AutoPostBack="false"  >                      
                </asp:CheckBoxList>

pls share ur ideas 请分享您的想法

You don't. 你没有。

Use a RadioButtonList and style the radio buttons as checkboxes . 使用RadioButtonList并将单选按钮设置为复选框样式


After clarification, this is what I would do: 经过澄清,这就是我要做的:

In javascript, attach to the click or change event of the checkboxes, and if any of the products are selected, uncheck the ALL checkbox. 在javascript中,附加到复选框的clickchange事件,如果选择了任何产品,则取消选中ALL复选框。

Of course, since this is client side, you would have to validate on the server side. 当然,由于这是客户端,因此您必须在服务器端进行验证。

Definitely there should be a custom logic involved because as far as I know no check box list has such a behavior. 绝对应该包含自定义逻辑,因为据我所知,没有复选框列表具有这种行为。

two ways has came to my mind that I'd like to suggest: 我想提出两种建议:

First, you can have an event handler in place that listens to the check box list and if the selected item has changed checks to see if it's the All item or not and if that is it will check all other items (or uncheck them ) This can be done using a javascript or if the control post back its state every time its state has changed then you can have it on code behind. 首先,您可以使用一个事件处理程序来侦听复选框列表,并且如果选定的项目已更改,则检查它是否为All项目,如果是,它将检查所有其他项目(或取消选中它们)。可以使用javascript完成,或者如果控件每次状态更改后都回发其状态,则可以将其放在后面的代码中。

Second, you can have another single check box next to your check box list that says " or select All " for example and if it's checked it disable the check box list. 第二,您可以在复选框列表旁边有另一个复选框,例如说“或选择全部”,如果选中,则禁用复选框列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM