|
-
Sep 9th, 2005, 10:05 AM
#1
Thread Starter
Member
multiple columns in DDList
How do I bind multiple columns to a drop down list.
I run a stored procedure to find a patient name.
I want to show the first and last name in the drop down list.
Here's a snipet:
If Not Page.IsPostBack Then
objSQLCmd = New SqlCommand
With objSQLCmd
.CommandText = "sp_GetPatientByName"
.CommandType = CommandType.StoredProcedure
.Connection = objConnection
.Parameters.Add("@LName", SqlDbType.Char).Value = strLName
.Parameters.Add("@FName", SqlDbType.Char).Value = strFName
End With
objDataAdapter = New SqlDataAdapter(objSQLCmd)
objDataSet = New DataSet
objDataAdapter.Fill(objDataSet)
ddlTest.DataSource = objDataSet
ddlTest.DataTextField = ("Last_Name")
'ddlTest.DataTextField = ("Last_Name" & ", " & "First_Name")
ddlTest.DataBind()
ddlTest.Items.Insert(0, "Select a Patient")
End If
Thanks in Advance!
Last edited by rothjm; Sep 9th, 2005 at 02:50 PM.
Reason: RESOLVED
-
Sep 9th, 2005, 10:47 AM
#2
Frenzied Member
Re: multiple columns in DDList
The DropDownList can't do what you want unfortunately unless you populate it manually i.e not using datasource etc. Perhaps you could concatenate the two names in the Stored Procedure.
Code:
SELECT Last_Name + ', ' + First_Name AS Full_Name
Then you could databind to Full_Name.
DJ
If I have been helpful please rate my post. If I haven't tell me!
-
Sep 9th, 2005, 11:03 AM
#3
Thread Starter
Member
Re: multiple columns in DDList
That would work.
But how could I capture the users input to use against the database?
I really need:
SELECT Last_Name + ', ' + First_Name + ': ' + Med_Rec# AS Full_Name
But how could I capture the Med_Rec# to use to find history from the database (once the user selects the correct patient)?
Thanks
-
Sep 9th, 2005, 11:22 AM
#4
Frenzied Member
Re: multiple columns in DDList
You'd load the Full_Name into the DataTextField and then the record number into the DataValueField. You can then access the SelectedValue to reference against the database.
DJ
If I have been helpful please rate my post. If I haven't tell me!
-
Sep 9th, 2005, 12:35 PM
#5
Thread Starter
Member
Re: multiple columns in DDList
 Originally Posted by dj4uk
You'd load the Full_Name into the DataTextField and then the record number into the DataValueField. You can then access the SelectedValue to reference against the database.
DJ
Can you show me code for that?
I am a rookie!
Thanks again!
-
Sep 9th, 2005, 12:45 PM
#6
Thread Starter
Member
Re: multiple columns in DDList *Resolved*
OK, I understand now.
Just:
ddlTest.DataValueField = "Med_Rec#"
I changed my stored_proc to make this work.
I really appreciate your help!!!
-
Sep 9th, 2005, 02:50 PM
#7
Thread Starter
Member
Re: multiple columns in DDList
I am still having some trouble with the SelectedValue.
I tried this:
txtMR.Text = ddlTest.SelectedValue
But it displays the "Select a Patient" before I select one and doesn't change when I do make a selection.
Can you show me how to correct this?
-
Sep 9th, 2005, 04:36 PM
#8
Frenzied Member
Re: multiple columns in DDList
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
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
|