The Following sample shows the method of binding dropdownlist dynamically. Hee "Name" is the Text Field of the dropdownlist and "id" is the value Field.
Dim str As String = "data source=(local);" _
& "initial catalog=av;uid=sa;pwd=sa;"
Dim con As SqlConnection = New SqlConnection(str)
con.Open()
Dim ds As New DataSet
Dim da As SqlDataAdapter
Dim strSql As String = "Select * from tabTest"
da = New SqlDataAdapter(strSql, con)
da.Fill(ds)
// ddl is the name of the dropdown list.
ddl.Datasoucre = ds.Tables(0)
ddl.DataTextField = "Name"
ddl.DataValueField = "id"
ddl.DataBind()
For Answers, see/post comments
Binding Data to DropdownList
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment