J
Jos Branders
I always get the value for the first entry in the list, regardless of whatmd said:Hello all -
I am having a goofy problem that I strongly suspect is a (gasp!) bug in my
code, but I can't for the life of me figure it out.
I have a Dropdownlist control on a page that is bound in code to a DataTable
object. That works fine, it shows the data. I select an item in the list
other than the first item, but when I click on a button and read the
.SelectedItem.Value property it always returns the value for the first item in the list.
I used the command window and displayed Dropdownlist1.Items(x).Value for
each item in the list (there are only three at the moment), and it displayed
the correct value, but when I try to use the .SelectedItem.Value property
was chosen.
Anybody run into this? I appreciate any help anyone can offer.
Matt
My guess is that you are databinding again on postback.
This causes your server to lose the state of your list.
Try changing your Page_Load event in something like this:
Sub Page_Load(Sender As Object, E As EventArgs)
If Not Page.IsPostBack Then
-----Bind your list here-----
End If
End Sub