Results 1 to 8 of 8

Thread: multiple columns in DDList

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2004
    Location
    KS, USA
    Posts
    34

    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

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    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!

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2004
    Location
    KS, USA
    Posts
    34

    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

  4. #4
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    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!

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2004
    Location
    KS, USA
    Posts
    34

    Re: multiple columns in DDList

    Quote 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!

  6. #6

    Thread Starter
    Member
    Join Date
    Nov 2004
    Location
    KS, USA
    Posts
    34

    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!!!

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2004
    Location
    KS, USA
    Posts
    34

    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?

  8. #8
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861

    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
  •  



Click Here to Expand Forum to Full Width