How to group CheckboxList?

E

Egbert

I use a System.Web.UI.WebControls.CheckBoxList object to fill a list.

I need to label groups of checkboxes in the list by Category (Determined
dynamically from the database) at runtime.

Is it possible to group checkboxes in 1 CheckboxList?

Something like this:

*************************

Category 1
-checkbox1
-checkbox2

Category 2
-checkbox3
-checkbox4

Category 3
-checbox5

*************************
 
J

Justin Rogers

There isn't any default grouping. You'd have to customize the control's
rendering
in order to provide this feature. Won't be exceptionally easy to do this using
the
existing control, so you might want to create your own control.
 
E

Egbert

You mean by using a Repeater or Datagrid?

But then it is difficult to determine which boxes are checked, and which
aren't, when you want to persist de results.

In case of 1 checkboxlist, you can loop through the items of the
checkboxlist.

I also tried to group de checkboxes by giving them the same name, like in
HTML, but that doesn't seem to be possible with <asp:checkbox> elements.
 
J

Justin Rogers

The CheckBoxList actually gives each checkbox a unique number
based on index. They are doing some work. The point is, if you
want this feature, you are going to have to get an existing control
or write your own logic.

ListControl is a good base class to start from. Or CheckBoxList
if you just override the rendering logic. Otherwise, you could use
your own Repeater, since that is pretty much what the CheckBoxList
does already.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top