Results 1 to 8 of 8

Thread: Checkbox List Item selected

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Checkbox List Item selected

    When a user clicks a checkbox in my checkbox list I want to get the column numer they clicked on. For example, if they click the first box the number should be 0, the second box should be 1, and so on.

    I tried this

    rblAlerts.SelectedIndex

    But this always return a 0 value no matter which check box is clicked. I have my code in the SelectedIndexChanged sub.

    I am using VB .Net 2003.

    Thanks
    David Wilhelm

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Checkbox List Item selected

    Do you have autopostback=True for the control?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Re: Checkbox List Item selected

    Yes the auto postback value is set to True. If it wasn't then nothing would happen when the user clicked on the check box list. Like I said before I am getting the 0 value back no matter which check box the user clicks on.
    David Wilhelm

  4. #4
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Checkbox List Item selected

    Do any of your items share the same value, but different display text?

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Checkbox List Item selected

    The event that handles the checkboxlist checkbox selection should have a... say, ItemIndex. So you can go

    e.Item.ItemIndex or e.ItemIndex.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Re: Checkbox List Item selected

    I don't think this works in the selectedindexchanged sub of either the radiobuttonlist control or the checkboxlist control. This is the only way that I could make it work.

    if radiobuttonList1.items(0).selected = true then blah

    if radiobuttonlist1.items(1).selected = true then blah

    It would be more efficient if I could get back the slected value in one line of code than having to check for all possible radio buttons that could be selected.
    David Wilhelm

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Re: Checkbox List Item selected

    I was wrong about the radiobuttonList. You can use radiobuttonList.selectedindex and that will give you the row that is selected.

    However, I don't think this is possible for the CheckBoxList since more than one of these can be checked.
    David Wilhelm

  8. #8
    New Member
    Join Date
    Sep 2006
    Posts
    1

    Re: Checkbox List Item selected

    Yes, you can get the clicked item ID by accessing

    Page.Request.Form["__EVENTTARGET"]

    in the event CheckboxList_SelectedIndexChanged.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width