简体   繁体   中英

how to use checkbox list as radio button

I have checkbox list, values are extacting from DB by button click. the vaues are ALL,Produc1,Product2. by default all is selected if i select Product1 "ALL" checkbox should uncheck.

<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 .


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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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