PDA

Click to See Complete Forum and Search --> : Dropdown List Help...


HollywoodKY
Jan 16th, 2004, 02:15 PM
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
:)

HollywoodKY
Jan 16th, 2004, 02:17 PM
Here's some code if it helps:

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.

Memnoch1207
Jan 16th, 2004, 03:23 PM
1)

lstUsers.DataTextField = "fldLastName" & ", " & "fldFirstName"
lstUsers.DataValueField = "PersonID" 'or whatever the pk is


2) Are you doing something like this

If(Page.IsPostBack) Then
'do this
End If

???

HollywoodKY
Jan 16th, 2004, 05:35 PM
Thanks for the help again...

1. I had originally tried that 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:

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


HWOODKY
:)