By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,534 Members | 1,830 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,534 IT Pros & Developers. It's quick & easy.

Listbox NOT retrieving Selected Index

P: n/a
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
ct******@pierceassociates.com

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


Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
ct******@pierceassociates.com

"Chris Thunell" <ct******@pierceassociates.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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
ct******@pierceassociates.com

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

Nov 18 '05 #2

P: n/a
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.

"Chris Thunell" <ct******@pierceassociates.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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
ct******@pierceassociates.com

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

Nov 18 '05 #3

P: n/a
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!

"Marina" <so*****@nospam.com> wrote in message
news:eW**************@tk2msftngp13.phx.gbl...
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.

"Chris Thunell" <ct******@pierceassociates.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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
ct******@pierceassociates.com

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


Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.