943,772 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 14617
  • ASP.NET RSS
Sep 18th, 2006
0

How to get a selected index from checklistbox

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Raju5725 is offline Offline
15 posts
since Sep 2006
Sep 18th, 2006
0

Re: How to get a selected index from checklistbox

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.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Sep 18th, 2006
0

Re: How to get a selected index from checklistbox

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Raju5725 is offline Offline
15 posts
since Sep 2006
Sep 18th, 2006
0

Re: How to get a selected index from checklistbox

Quote ...
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.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Sep 18th, 2006
0

Re: How to get a selected index from checklistbox

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Raju5725 is offline Offline
15 posts
since Sep 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: How to link Tab and combine the value in database
Next Thread in ASP.NET Forum Timeline: file open dialog box control in asp.net





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC