Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop Down List not working 1

Status
Not open for further replies.

headguru

Programmer
Oct 7, 2002
4
0
0
US
HI,
I have a databound drop down list. It gets the data from the SQL db fine, but when selecting a new choice the .selecteditem never changes. So if it loads A,B,C,D the selected item is always A no matter what I select. Code below, thanks for the help.

This binds it:
con.Open()
txtVCP.DataSource = com.ExecuteReader
txtVCP.DataTextField = "VCP"
txtVCP.DataBind()
con.Close()

All the data is fine


Private Sub txtVCP_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtVCP.SelectedIndexChanged
Dim vcp As String
vcp = txtVCP.SelectedItem.Value

End Sub

VCP always = A, no matter whats selected.

 
When do you call the code that does the databinding? If it is called from "Page_Load", then it will rebind the data before the "txtVCP_SelectedIndexChanged" code is run, which will cause the value to always be A.

If it is called from the Page_Load function, you may need to make sure it is only called the first time the page is loaded:

if not page.isPostBack then
'do databinding
end if

HTH! Kevin B.
.Net Programmer [thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top