Hi,
I am using a checkbox list populated at the design time itself. The list has about 25 items. In the SelectedIndexChanged event, the SelectedIndex of the checkbox list always returns the lowest selected index of the list instead of what I clicked on.
So if item 3 is checked and I check on item 10, the selected index of
the control is always 3. How can I get the index of what was selected?
The eventArgs is empty.
It would be nice if I could find out which checkbox was clicked. Does anyone know how to do that?

Thanks in advance

The possible problems causing this behaviour are:

You are populating the list at runtime, and dont have if(!IsPostBack) block around the code that populates the list. Which causes the ist to be re-set before it gets to the indexchange event handler.

You have viewstate disabled for the control or page, meaning nothings is saved.

You are referencing the selected index too early in the page lifecycle, before the contols have been re-built server-side and populated from the viewstate.

I am not populating the list at runtime, I am populating at the design time itself. so there is no need of if(!IsPostBack) block.
both for the control and page view state is true.

how can i verify your last statement.

Thanks
Raju

The possible problems causing this behaviour are:

You are populating the list at runtime, and dont have if(!IsPostBack) block around the code that populates the list. Which causes the ist to be re-set before it gets to the indexchange event handler.

You have viewstate disabled for the control or page, meaning nothings is saved.

You are referencing the selected index too early in the page lifecycle, before the contols have been re-built server-side and populated from the viewstate.

So if item 3 is checked

Where is this checked ? in Page_Load ? or design time (in aspx page)?

Can you post the relevant parts of your aspx and apsx.cs please.

Here is my code:
aspx.vb
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If IsPostBack = True Then
ChkList_SelectedIndexChanged(ChkList, e)

End If

End Sub
Private Sub ChkList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ChkList.SelectedIndexChanged
Dim I as integer
I=ChkList.SelectedIndex()
Response.write(I)
End Sub

Where is this checked ? in Page_Load ? or design time (in aspx page)?

Can you post the relevant parts of your aspx and apsx.cs please.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.