How to get a selected index from checklistbox

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 15
Reputation: Raju5725 is an unknown quantity at this point 
Solved Threads: 0
Raju5725 Raju5725 is offline Offline
Newbie Poster

How to get a selected index from checklistbox

 
0
  #1
Sep 18th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: How to get a selected index from checklistbox

 
0
  #2
Sep 18th, 2006
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.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 15
Reputation: Raju5725 is an unknown quantity at this point 
Solved Threads: 0
Raju5725 Raju5725 is offline Offline
Newbie Poster

Re: How to get a selected index from checklistbox

 
0
  #3
Sep 18th, 2006
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

Originally Posted by hollystyles View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: How to get a selected index from checklistbox

 
0
  #4
Sep 18th, 2006
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.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 15
Reputation: Raju5725 is an unknown quantity at this point 
Solved Threads: 0
Raju5725 Raju5725 is offline Offline
Newbie Poster

Re: How to get a selected index from checklistbox

 
0
  #5
Sep 18th, 2006
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

Originally Posted by hollystyles View Post
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC