468,290 Members | 2,025 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,290 developers. It's quick & easy.

Listbox NOT retrieving Selected Index

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
3 1508
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
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
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.

Similar topics

3 posts views Thread by amber | last post: by
5 posts views Thread by Dave H | last post: by
3 posts views Thread by Mitch | last post: by
7 posts views Thread by Lit | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.