I have a dropdownlist
that I want to populate with a specific value and specific text. I'm not using a datasource
but I am manually making a connection and retrieving data in code. How can I populate this dropdownlist
? If I read the data with a datareader
and increment an array I only get either the value or the text. This is what I have so far, but it is completely wrong:
//connection string etc goes here
Dbcmd2.CommandText = "select dept,deptname from table"
Dim dr As SqlClient.SqlDataReader
dr = Dbcmd2.ExecuteReader
Dim i As Integer
Dim arydept As New arraylist
While dr.Read
arydept.Add(dr1("dept"))
End While
ddldept.datasource = arydept
ddldept.DataTextField = ????????
ddldept.DataValueField = dr("dept")
ddldept.DataBind()
How can I get this to work without having to create a class object for Department
? Is there anyway or should I create the class object?