|
-
Jan 16th, 2004, 03:15 PM
#1
Thread Starter
Member
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
-
Jan 16th, 2004, 03:17 PM
#2
Thread Starter
Member
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.
-
Jan 16th, 2004, 04:23 PM
#3
Frenzied Member
1)
Code:
lstUsers.DataTextField = "fldLastName" & ", " & "fldFirstName"
lstUsers.DataValueField = "PersonID" 'or whatever the pk is
2) Are you doing something like this
VB Code:
If(Page.IsPostBack) Then
'do this
End If
???
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Jan 16th, 2004, 06:35 PM
#4
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|