DropDownList selectedIndex is not updated

W

Wanda

Hi,

I am trying to read the DropDownList's selectedIndex when it fires the
event
"SelectedIndexChanged", however, the index value is always 0 no matter
what I've clicked. I just wonder what have I done wrong in my code...

This is how I populate my list at the Page_Load!!!!


Dim myCMD As SqlCommand = New SqlCommand(strSQL, cn)
Dim myReader As SqlDataReader = myCMD.ExecuteReader()
Dim fNextResult As Boolean = True

lstEmployee.Items.Clear()
Do Until Not fNextResult
Do While myReader.Read()
If Not myReader.IsDBNull(0) Then
lstEmployee.Items.Add(New
ListItem(myReader.GetString(1), myReader.GetInt32(0)))
End If
Loop
fNextResult = myReader.NextResult()
Loop
myReader.Close()


Thanks in advance. Any help will be greatly appreciated.
Wanda
 
K

Karl

Assume from potential readiability problems with the code, make sure it's
wrapped in an:

If Not Page.IsPostBack Then
... 'put your code in here
end if

Otherwise, on postback, your ddl is repopulated and its selected value lost.

Karl
 

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
474,262
Messages
2,571,045
Members
48,769
Latest member
Clifft

Latest Threads

Top