checkboxlist - determine checkbox that caused control to fire

Discussion in 'ASP .Net' started by Guest, Jul 28, 2007.

  1. Guest

    Guest 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!
    Guest, Jul 28, 2007
    #1
    1. Advertising

  2. Guest

    Masudur Guest

    On Jul 28, 7:09 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.
    >
    > 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
    Masudur, Jul 28, 2007
    #2
    1. Advertising

  3. Guest

    Riki Guest

    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
    Riki, Jul 28, 2007
    #3
  4. Guest

    Guest 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

    "Riki" <> wrote in message
    news:...
    > 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
    >
    Guest, Jul 28, 2007
    #4
  5. Guest

    PG Deep Guest

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


    >>> 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/tutorial...-parameters--types--multiple-row-inserts.aspx
    PG Deep, Jan 29, 2011
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aaron Chorpenning

    Re: How to determine Control that caused Postback?

    Aaron Chorpenning, Jul 21, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    463
    Aaron Chorpenning
    Jul 21, 2003
  2. JD
    Replies:
    5
    Views:
    11,616
    NetArchitect
    Aug 8, 2007
  3. Patrick.O.Ige
    Replies:
    5
    Views:
    19,071
    Patrick.O.Ige
    Jun 19, 2005
  4. Jordan
    Replies:
    3
    Views:
    3,007
    Stefan
    Aug 31, 2005
  5. TS
    Replies:
    5
    Views:
    3,226
    Juan T. Llibre
    Nov 29, 2005
Loading...

Share This Page