Results 1 to 2 of 2

Thread: Setting selected dropdownlist item.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 1999
    Posts
    165

    Question Setting selected dropdownlist item.

    How is best to set the selected item in a drop down list, from code, which is bound to a dataset?

    Many thanks.

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    here's one way:
    VB Code:
    1. Private Sub bindAuthors()
    2.     Dim connString As String = "user id=sa;password=sa;database=pubs;server=manson;"
    3.     Dim cn As SqlConnection = New SqlConnection(connString)
    4.     Dim cmdText As String = "Select au_id As AuthorId, " & _
    5.                             "au_lname + ', ' + au_fname as AuthorFullName " & _
    6.                             "From Authors"
    7.     Dim da As SqlDataAdapter
    8.     Dim ds As New DataSet("Authors")
    9.     da = New SqlDataAdapter(cmdText, cn)
    10.     da.Fill(ds)
    11.     Authors.DataSource = ds
    12.     Authors.DataTextField = "AuthorFullName"
    13.     Authors.DataValueField = "AuthorId"
    14.     Authors.DataBind()
    15.     Authors.SelectedIndex = 5
    16. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width