Results 1 to 4 of 4

Thread: Dropdown List Help...

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    53

    Exclamation Dropdown List Help...

    Here's the problem, I have a drop down list on a page. It is currently filled on load/postback with a LastName field from an Access database. I have two questions:

    1. I have some duplicate last names (Smith, Jones, etc.) so there is no way to tell which record I am selecting. Is there a way to fill the dropdown list with TWO fields (LastName, FirstName)?

    2. Last, when my page postsback, the dropdown list goes back to the original name it loads with (in this case "Adams"). If I select ("Smith"), the autopostback fires and the correct data fills the textboxes, but now the dropdownlist shows "Adams". I would like to know if there is a way to make it stay on "Smith".

    Thanks as always, I'm sure this is something fairly simple but I don't know where to begin searching.

    HWOODKY

  2. #2

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    53
    Here's some code if it helps:

    Code:
    Dim connStringRPP As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                                   "data source=d:\test.mdb"
            Dim cnRPP As New OleDb.OleDbConnection(connStringRPP)
            Dim cmdTextRPP As String = "SELECT * FROM Bio ORDER BY fldLastName ASC"
            Dim cmdRPP As New OleDb.OleDbCommand(cmdTextRPP, cnRPP)
            Dim daRPP As New OleDb.OleDbDataAdapter(cmdRPP)
            Dim dsRPP As New DataSet()
            daRPP.FillSchema(dsRPP, SchemaType.Source, "Bio")
            daRPP.Fill(dsRPP, "Bio")
    
            lstUsers.DataSource = dsRPP
            lstUsers.DataBind()
    lstUsers is the dropdownlist.

  3. #3
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    1)
    Code:
    lstUsers.DataTextField = "fldLastName" & ", " & "fldFirstName"
    lstUsers.DataValueField = "PersonID" 'or whatever the pk is
    2) Are you doing something like this
    VB Code:
    1. If(Page.IsPostBack) Then
    2.    'do this
    3. End If
    ???
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    53
    Thanks for the help again...

    1. I had originally tried that code:

    Code:
    Dim connStringRPP As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                                   "data source=d:\test.mdb"
            Dim cnRPP As New OleDb.OleDbConnection(connStringRPP)
            Dim cmdTextRPP As String = "SELECT * FROM Bio ORDER BY fldLastName ASC"
            Dim cmdRPP As New OleDb.OleDbCommand(cmdTextRPP, cnRPP)
            Dim daRPP As New OleDb.OleDbDataAdapter(cmdRPP)
            Dim dsRPP As New DataSet()
            daRPP.FillSchema(dsRPP, SchemaType.Source, "Bio")
            daRPP.Fill(dsRPP, "Bio")
    
            lstUsers.DataSource = dsRPP
            lstUsers.DataTextField = "fldLastName" & ", " & "fldFirstName"
            lstUsers.DataValueField = "fldID"
            lstUsers.DataBind()
    However, it produces this error:
    DataBinder.Eval: 'System.Data.DataRowView' does not contain a property with the name fldLastName, fldFirstName.
    2. Yes, I am using that code in the Page Load event. The dropdownlist is autopostback. Looks like this:

    Code:
    If Page.IsPostBack = False Then
                LoadUsers()
            Else
                ReLoadUsers()
            End If

    HWOODKY

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