Last post Oct 28, 2009 11:40 AM by LWCARAB
Oct 28, 2009 10:42 AM|LWCARAB|LINK
Here is the code I'm using:
Public Sub PopulateUsers()
Dim strConn As String = "Server=#; Database=#; Uid=#; Pwd=#; Allow Zero Datetime=true"
Dim conn As New MySqlConnection(strConn)
Dim cmd As New MySqlCommand("SELECT * FROM Visits", conn)
Dim dr As MySqlDataReader
Catch ex As Exception
dr = cmd.ExecuteReader()
ddlUsers.DataSource = dr
ddlUsers.DataTextField = "VisitID"
ddlUsers.DataValueField = "VisitID"
It populates the list just fine but when I come to use a selected item from the drop down list with say the code below:
Protected Sub btbSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btbSearch.Click
It always displays the value of the first item in the dropdown list whatever item I select.
What am I missing? Or am I really just going mad?
Oct 28, 2009 11:14 AM|RabidK|LINK
First, make sure you are only populating the list if you are not is a PostBack condition. Otherwise, you will repopulate it every time you postback.
Oct 28, 2009 11:15 AM|SynergyNT|LINK
I REALLY hope that is not the actual database login information you posted there.
Oct 28, 2009 11:31 AM|LWCARAB|LINK
Postback is disabled however PopulateUsers is run on pageload, can't see a way round that?
Oct 28, 2009 11:32 AM|LWCARAB|LINK
Thanks SynergyNT, it was but had now been changed, no data of interest in there anyway... I'll add it to my list of failures today!
Oct 28, 2009 11:35 AM|RabidK|LINK
Postback must be happening since your code in the Event handler for the Click event is working... The button click is firing the Postback.
So try this. Wrap your call to the PopulateUsers method as such:
If Not IsPostback Then
Oct 28, 2009 11:40 AM|LWCARAB|LINK