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