selectedindex value not being updated

B

bill yeager

I have a listbox whose autopostback property is set
to 'true'. When this event fires, I have code in
the 'SelectedIndexChanged' event to capture the
selectedindex of the listbox to be reset on the listbox
when the postback occurs. However, the selectedindex
property is alway -1.

Below is the code prior to selecting an item for this
listbox. Right after I select an item, the following code
executes, which I'm expecting, but
the "lstRider.SelectedIndex" value is -1, and I don't know
why.......
<code>
Private Sub lstRider_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
lstRider.SelectedIndexChanged

viewstate.Item("Rider1Idx") =
lstRider.Items.Item(lstRider.SelectedIndex).Value()

End Sub
</code>

Can anybody inform me how I can capture the index of the
selected item in the list???
 
C

carlos medina

maybe you are binding the listbox each time that the page is loaded.... you
can control it using Page.IsPostBack..

If Not Page.IsPostBack Then
BindListBox()
End If

public sub BindListBox()
' code to bind the listbox
end sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top