ListBox index values

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.
 
G

Guest

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
 
G

Guest

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.
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top