Home All Groups Group Topic Archive Search About

HELP: Dynamic updateable checkbox list

Author
9 Feb 2006 5:38 AM
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!

Author
9 Feb 2006 6:32 AM
Phillip Williams
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.

Show quoteHide quote
"Usenet User" wrote:

> 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!
>
Author
10 Feb 2006 7:22 PM
Usenet User
On Wed, 8 Feb 2006 22:32:27 -0800, "Phillip Williams"
<WEBSWAPP@newsgroups.nospam> wrote:

Show quoteHide quote
>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!