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
Re: Checkbox List Item selected
Do you have autopostback=True for the control?
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.
Re: Checkbox List Item selected
Do any of your items share the same value, but different display text?
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.
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.
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.
Re: Checkbox List Item selected
Yes, you can get the clicked item ID by accessing
Page.Request.Form["__EVENTTARGET"]
in the event CheckboxList_SelectedIndexChanged.