Listbox NOT retrieving Selected Index

C

Chris Thunell

I have a Listbox on an vb aspx web page. When i select something in the
listbox i do not get a selected value or selected index. The selected index
is always -1.

Any thoughts would be greatly appreciated!
Chris Thunell
(e-mail address removed)

Here is my code:
loading:

Me.lbPending.DataSource = dvPending 'dvpending is a dataview, but i've
tried a dataset as well - no luck.
Me.lbPending.DataTextField = "DateName"
Me.lbPending.DataValueField = "BidNo"
Me.lbPending.DataBind()

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button12.Click

Label7.Text = (lbPending.SelectedItem.Value.ToString) 'this always
returns -1

End Sub
 
C

Chris Thunell

Just an additional thought.... both selectedvalue and selectedindex don't
work.
I created a new project with just the listbox and code similar to below -
Nothin!
Thanks again for your help!
Chris Thunell
(e-mail address removed)
 
M

Marina

If you are running the binding code every time, then that is the problem. If
you are rebinding on postback, that discards all the current values (as well
as the selection information) and rebinds the dropdown again.
Make sure the binding code is in a 'If Not IsPostback Then' block.
 
C

Chris Thunell

That was it!!!! Geez something so simple.. i've spent 2 hours trying to
figure this one out! :) Thank you so much for your help!
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top