How is best to set the selected item in a drop down list, from code, which is bound to a dataset?
Many thanks.here's one way:
Private Sub bindAuthors()
Dim connString As String = "user id=sa;password=sa;database=pubs;server=manson;"
Dim cn As SqlConnection = New SqlConnection(connString)
Dim cmdText As String = "Select au_id As AuthorId, " & _
"au_lname + ', ' + au_fname as AuthorFullName " & _
"From Authors"
Dim da As SqlDataAdapter
Dim ds As New DataSet("Authors")
da = New SqlDataAdapter(cmdText, cn)
da.Fill(ds)
Authors.DataSource = ds
Authors.DataTextField = "AuthorFullName"
Authors.DataValueField = "AuthorId"
Authors.DataBind()
Authors.SelectedIndex = 5
End Sub
Monday, March 26, 2012
Setting selected dropdownlist item.
Labels:
asp,
bound,
code,
datasetmany,
drop,
dropdownlist,
item,
net,
selected,
setting
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment