S
Scott D
I am currently binding my dropdownlists from a database using the
logic below. And they are populated correctly.
My problem is when I go to submit the information to the database
using Me.ddSID.DataValueField no matter what is selected from the
dropdown a blank string is passed to the methods within my codebehind.
I thought after binding in this fashion I would be passed the
information in the VALUE field which should be the SID. Any ideas why
I am not being passed the value?
Private Sub ddSIDBind()
Dim connString As String =
"server=servername;uid=UN;pwd=PWD;Initial Catalog=DB"
Dim conn As SqlConnection = New SqlConnection(connString)
Dim sql As String = "SELECT * FROM tblSales ORDER BY SName"
Dim cmd As SqlCommand = New SqlCommand(sql, conn)
conn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
Me.ddSID.DataSource() = dr
While dr.Read
Dim newListItem As New ListItem()
newListItem.Value = dr("SID")
newListItem.Text = dr("SName")
Me.ddSID.Items.Add(newListItem)
End While
dr.Close()
conn.Close()
End Sub
logic below. And they are populated correctly.
My problem is when I go to submit the information to the database
using Me.ddSID.DataValueField no matter what is selected from the
dropdown a blank string is passed to the methods within my codebehind.
I thought after binding in this fashion I would be passed the
information in the VALUE field which should be the SID. Any ideas why
I am not being passed the value?
Private Sub ddSIDBind()
Dim connString As String =
"server=servername;uid=UN;pwd=PWD;Initial Catalog=DB"
Dim conn As SqlConnection = New SqlConnection(connString)
Dim sql As String = "SELECT * FROM tblSales ORDER BY SName"
Dim cmd As SqlCommand = New SqlCommand(sql, conn)
conn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
Me.ddSID.DataSource() = dr
While dr.Read
Dim newListItem As New ListItem()
newListItem.Value = dr("SID")
newListItem.Text = dr("SName")
Me.ddSID.Items.Add(newListItem)
End While
dr.Close()
conn.Close()
End Sub