ListBox index values

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,

I would like to display the values of the index as chosen by the user in a
listbox. These values would be as per the datavaluefield. On testing I get
a value of -1:

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Me.Label1.Text = ListBox1.Items.Item(2).Text
End Sub

I would like to replace the "2" with the item the user selects. Any help
appreciated.
 
hi,
you can get the selected value of the listbox at the server side using
ListBox1.SelectedItem.Value .
so try using Me.Label1.Text = ListBox1.SelectedItem.Value
 
hi niggy,
are you binding the listbox at runtime? if so check that the listbox has
items after postback.. you are getting this error probably becoz the listbox
has no selected item.i think you are binding the listbox on postback.
 
Back
Top