Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > checkboxlist - determine checkbox that caused control to fire

Reply
Thread Tools

checkboxlist - determine checkbox that caused control to fire

 
 
Guest
Posts: n/a
 
      07-28-2007
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!


 
Reply With Quote
 
 
 
 
Masudur
Guest
Posts: n/a
 
      07-28-2007
On Jul 28, 7:09 am, <(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
 
 
 
Riki
Guest
Posts: n/a
 
      07-28-2007
http://www.velocityreviews.com/forums/(E-Mail Removed)am wrote:
> 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.

--

Riki


 
Reply With Quote
 
Guest
Posts: n/a
 
      07-28-2007
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

"Riki" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> (E-Mail Removed)am wrote:
>> 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.
>
> --
>
> Riki
>



 
Reply With Quote
 
PG Deep
Guest
Posts: n/a
 
      01-29-2011
for (int k = 0; k < chklConditionCodes.Items.Count; k++)
{ if(chklConditionCodes.Items[k].Selected == true)
{
if (chklConditionCodes.Items[k].Text == "xxx")
{
//ur logic here
}
}
}


> On Friday, July 27, 2007 9:09 PM <para wrote:


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



>> On Saturday, July 28, 2007 4:05 AM Masudur wrote:


>> On Jul 28, 7:09 am, <(E-Mail Removed)> wrote:
>>
>> 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



>>> On Saturday, July 28, 2007 9:30 AM Riki wrote:


>>> (E-Mail Removed)am wrote:
>>>
>>> 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.
>>>
>>> --
>>>
>>> Riki



>>>> On Saturday, July 28, 2007 1:32 PM <para wrote:


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



>>>> Submitted via EggHeadCafe
>>>> SQL Server Table Valued Parameters / Types - Multiple Row Inserts
>>>> http://www.eggheadcafe.com/tutorials...w-inserts.aspx

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Checkboxlist inside Repeater - doesn't fire click event for Checkboxlist JD ASP .Net 5 08-08-2007 11:28 AM
how do i determine what event caused postback TS ASP .Net 5 11-29-2005 03:39 PM
How To Determine What Caused PostBack Jordan ASP .Net 3 08-31-2005 07:48 PM
Re: How to determine Control that caused Postback? Aaron Chorpenning ASP .Net 0 07-21-2003 04:18 PM



Advertisments