Hi,
I'm trying to bind a DropDownList in the code behind using the following code:

Dim DatabaseConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("myServer").ConnectionString)
Dim selectCMD As String = “SELECT name, id FROM Clients WHERE name LIKE @name + ‘%’”
Dim selectCMD As New SqlCommand(selectSQL, DatabaseConnection)
selectCMD.Parameters.Add(New SqlParameter("@name", SqlDbType.VarChar))
selectCMD.Parameters("@name").Value = name

Dim adapter As New SqlDataAdapter
Dim dTable As New DataTable
adapter.SelectCommand = selectCMD
adapter.Fill(dTable)

ddl.DataSource = dTable
ddl.DataBind()

But the values that are being bound to the DDL are all = System.Data.DataRowView. Any ideas of what is wrong?

ddl.DataSource = dTable
ddl.DataTextField = "name"
ddl.DataValueField="id"
ddl.DataBind()

Hi Adatapost,

Thanks a lot! Now it works perfectly! =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.