ram
ram

Reputation: 57

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

Upvotes: 1

Views: 3234

Answers (2)

Beatles1692
Beatles1692

Reputation: 5320

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.

Upvotes: 1

Oded
Oded

Reputation: 499022

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.

Upvotes: 2

Related Questions