DropDownList always returns value at index 0

N

Nathan Sokalski

I have a form that contains a DropDownList. When I submit the form and
attempt to use the DropDownList's value (I am doing this by using the
..SelectedValue property), I always recieve the value at index 0. What could
be causing this? Any help would be appreciated. Thanks.
 
L

Lucas Tam

I have a form that contains a DropDownList. When I submit the form and
attempt to use the DropDownList's value (I am doing this by using the
.SelectedValue property), I always recieve the value at index 0. What
could be causing this? Any help would be appreciated. Thanks.

Are you rebinding the drop down on each postback?
 
S

Siva M

Possibly you are filling the dropdown on postback also. Check it is done
only on initial page load:

If (Not PostBack) Then
// Fill drop-down
End If

I have a form that contains a DropDownList. When I submit the form and
attempt to use the DropDownList's value (I am doing this by using the
..SelectedValue property), I always recieve the value at index 0. What could
be causing this? Any help would be appreciated. Thanks.
 
C

Cor Ligthert [MVP]

Nathan,

How did you fill your dropdownlist.
If that is by a datasource, did you than restore your datasource at PostBack
time?

\\\
If Not IsPostBack then
fill ds
Session.Item(ds) = ds
Else
ds = Session.Item(ds)
End if
////

And don't forget to databind it at the last instruction before your sent
back

I hope this helps,

Cor
 
N

Nathan Sokalski

Thank you all, I don't know why I keep making this same mistake. I simply
needed to put my binding method in the Page_Init instead of Page_Load. But
thank you for using the key word init that reminded me of the simple
solution that took me forever to find in the past.
 

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,007
Latest member
obedient dusk

Latest Threads

Top