HELP: Dynamic updateable checkbox list

U

Usenet User

The task is simple: to display a databound list of checkboxes on a
page. Each check/uncheck should cause a postback, during which an
action must be taken based on which checkbox changed its value and the
value itself.

Oddly enough, I couldn't find a simple solution for the above problem.
I tried the most obvious: a CheckBoxList. This control exposes only
one appropriate event, SelectedIndexChanged, where I can iterate
through *all* items and find out their values. But this won't tell me
which of the inner checkboxes changed it's value. I would need to
maintain a separate collection of the last states and figure out the
difference manually. In addition, corresponding data keys are not
available.

Another attempted approach: a DataList with a CheckBox within its
ItemTemplate. Seems better because this would also give me the
corresponding key for each item. However, I couldn't find how to
determine when any checkbox changes it's value. (AutoPostBack is set
to true) Unlike buttons, CheckBox doesn't have CommandName property,
therefore the ItemCommand event of the DataList doesn't fire and I am
not sure how else I would catch the checkbox events.

After that I am lost. Does anyone have any other suggestion?

TIA!
 
G

Guest

Look at this sample using a Repeater:
http://www.societopia.net/Samples/Repeater_Hierarchy.aspx

and this sample using a datalist:
http://www.societopia.net/Samples/DataList_Hierarchy.aspx

Both the above samples use a radio button instead of a checkbox but the
process of handling the events should be the same.

You can also check this example using a DataGrid:
http://www.societopia.net/Samples/DataGrid_ChildControlsEvents.aspx

And this example using a GridView in ASP.NET 2.0
http://www.webswapp.com/codesamples/aspnet20/gridview_multiplerows_selection/default.aspx

The last 2 samples use the checkbox.
 
U

Usenet User

Look at this sample using a Repeater:
http://www.societopia.net/Samples/Repeater_Hierarchy.aspx

and this sample using a datalist:
http://www.societopia.net/Samples/DataList_Hierarchy.aspx

Both the above samples use a radio button instead of a checkbox but the
process of handling the events should be the same.

You can also check this example using a DataGrid:
http://www.societopia.net/Samples/DataGrid_ChildControlsEvents.aspx

And this example using a GridView in ASP.NET 2.0:
http://www.webswapp.com/codesamples/aspnet20/gridview_multiplerows_selection/default.aspx

The last 2 samples use the checkbox.


Thanks! While I couldn't find the simplest solution I was looking for,
you DataGrid example pointed out one important thing I was missing:

- Using HTML view, one still can add event handlers to controls within
item templates, even if the events are not exposed in the designer.

Thanks again!
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top