checkboxlist - determine checkbox that caused control to fire

G

Guest

Hi all,

I have a CheckBoxList control which has about 10 items. I have set
autopostback=true and also set an eventhandler for OnSelectedIndexChanged.
The problem is I want to identify which checkbox item caused the event to
fire to perform some routines based upon the value of that individual
checkbox. How can I determine this? For example, 5 of the 10 items maybe
checked. However, when I uncheck one, I want to perform some code based upon
the value of just that 1 checkbox that fired the event.

TIA!
 
M

Masudur

Hi all,

I have a CheckBoxList control which has about 10 items. I have set
autopostback=true and also set an eventhandler for OnSelectedIndexChanged.
The problem is I want to identify which checkbox item caused the event to
fire to perform some routines based upon the value of that individual
checkbox. How can I determine this? For example, 5 of the 10 items maybe
checked. However, when I uncheck one, I want to perform some code based upon
the value of just that 1 checkbox that fired the event.

TIA!

HI...

in the OnSelectedIndexChanged eventhandler you access selectedItem..
and more hover you can loop through the items on the items of the
checkboxlist... you can check the value... or to some extent you can
also add custom attribute to your item... then check the value and
perhaps attribute to do your job....
could you give a example exactly what are you trying to accomplish...

Thanks
Md. Masudur Rahman (Munna)
Kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com
 
R

Riki

Hi all,

I have a CheckBoxList control which has about 10 items. I have set
autopostback=true and also set an eventhandler for
OnSelectedIndexChanged. The problem is I want to identify which
checkbox item caused the event to fire to perform some routines based
upon the value of that individual checkbox. How can I determine this?
For example, 5 of the 10 items maybe checked. However, when I uncheck
one, I want to perform some code based upon the value of just that 1
checkbox that fired the event.

You can't identify which checkbox caused the event to fire, because several
may be selected, and the control doesn't keep track of which one was changed
(it does keep track internally, but it doesn't let you know).

You'll have to store the list of selected items before the postback in
ViewState, and compare this with the selected items after postback.

Another option might be to replace the checkboxlist with a set of separate
checkboxes, and link them all to the same OnCheckedChanged handler. The
first parameter of the event handler (sender) will refer to the checkbox
that caused the postback.
 
G

Guest

Maybe MS should consider opening up that hidden property to let me know
which checkbox fired the event in the CheckBoxList.

Anyways, I like your second idea. Maybe, I will give that a shot.

thanks
 
P

PG Deep

for (int k = 0; k < chklConditionCodes.Items.Count; k++)
{ if(chklConditionCodes.Items[k].Selected == true)
{
if (chklConditionCodes.Items[k].Text == "xxx")
{
//ur logic here
}
}
}
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top