selectedindex value not being updated

  • Thread starter Thread starter bill yeager
  • Start date Start date
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???
 
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
 
Back
Top