ListBox Help!

Cassio

Well-known member
Joined
Nov 30, 2002
Messages
276
Location
Rio de Janeiro
How can I retrieve the selected item from a listbox in ASP.NET?

I tried this:
Code:
        Dim i As Integer
        For i = 0 To lstProdutos.Items.Count - 1
            If lstProdutos.Items(i).Selected Then
                Response.Write(i)
            End If
        Next

and this:
Code:
Response.Write(lstProdutos.SelectedItem.Text)

And when I select an item and press the button it is like no item has been selected.
 
I normally check if the the control has an index using:
Code:
If lstProdutos.SelectedIndex <> -1 Then

However, if this doesnt work you will need to give me a bit more information to work with.

John
 
I figured it out. The problem was that I was using a datareader to fill the ListBox, just like I use to do in a Windows app, and was not using the databind method
When I used a DataSet it worked out fine.

Thanks.
 
Back
Top