| | |
How to get a selected index from checklistbox
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2006
Posts: 15
Reputation:
Solved Threads: 0
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
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.
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.
•
•
Join Date: Sep 2006
Posts: 15
Reputation:
Solved Threads: 0
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
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
Can you post the relevant parts of your aspx and apsx.cs please.
•
•
Join Date: Sep 2006
Posts: 15
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- please anybody to help Dropdownlist selected index problem (ASP.NET)
- In The DropDownList..If I have Five Names..when I click each name its index is 0 (VB.NET)
- Help with dropdownlist data adding? (VB.NET)
- JComboBox -- Item is not in the list???????? (Java)
Other Threads in the ASP.NET Forum
- Previous Thread: How to link Tab and combine the value in database
- Next Thread: file open dialog box control in asp.net
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox click commonfunctions compatible confirmationcodegeneration content contenttype countryselector courier css dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dropdownmenu edit expose flash flv formatdecimal forms formview gridview homeedition iframe iis javascript jquery list listbox login menu microsoft mono mouse mssql multistepregistration nameisnotdeclared news numerical objects order panelmasterpagebuttoncontrols problem radio ratings reportemail rotatepage save schoolproject search security serializesmo.table silverlight smartcard software sql-server sqlserver2005 suse textbox tracking unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webprogramming webservice xml youareanotmemberofthedebuggerusers






