Access more than 2 fields with Dropdown list

Discussion in 'ASP .Net Web Controls' started by Elsa Luiz, Nov 14, 2003.

  1. Elsa Luiz

    Elsa Luiz Guest

    Hi,
    I would like to access the value of a third field of the query that I
    used to populate my dropdown list. Is there a way to do that? For
    example, in the following example I would like to access valueC.

    SqlCommand sqlCmdLoad1 = new SqlCommand("SELECT valueA, valueB, valueC
    FROM myTable", sqlConnection1);
    sqlConnection1.Open();
    SqlDataReader dr1 = sqlCmdLoad1.ExecuteReader();
    ddl.DataSource = dr1;
    ddl.DataTextField = "valueA";
    ddl.DataValueField = "valueB";
    ddl.DataBind();
    dr1.Close();
    sqlConnection1.Close();

    I know that to access valueA I would use: ddl.SelectedItem.Text for
    example, to access valueB I would use: ddl.SelectedValue, and to
    access valueC, is there any way?

    Thanks,
    Elsa
     
    Elsa Luiz, Nov 14, 2003
    #1
    1. Advertising

  2. Elsa Luiz

    Teemu Keiski Guest

    Hi,

    on such cases you could create the value field to be one concatenated field
    (that's done in SQL, separator could be say a comma) which is then assigned
    to DataValueField property of DDL. When you access the value, you could get
    what you need by splitting the value with comma.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist

    "Elsa Luiz" <> wrote in message
    news:...
    > Hi,
    > I would like to access the value of a third field of the query that I
    > used to populate my dropdown list. Is there a way to do that? For
    > example, in the following example I would like to access valueC.
    >
    > SqlCommand sqlCmdLoad1 = new SqlCommand("SELECT valueA, valueB, valueC
    > FROM myTable", sqlConnection1);
    > sqlConnection1.Open();
    > SqlDataReader dr1 = sqlCmdLoad1.ExecuteReader();
    > ddl.DataSource = dr1;
    > ddl.DataTextField = "valueA";
    > ddl.DataValueField = "valueB";
    > ddl.DataBind();
    > dr1.Close();
    > sqlConnection1.Close();
    >
    > I know that to access valueA I would use: ddl.SelectedItem.Text for
    > example, to access valueB I would use: ddl.SelectedValue, and to
    > access valueC, is there any way?
    >
    > Thanks,
    > Elsa
     
    Teemu Keiski, Nov 14, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sky
    Replies:
    2
    Views:
    2,298
  2. =?Utf-8?B?SklNLkgu?=

    Q: multiple fields in dropdown list

    =?Utf-8?B?SklNLkgu?=, Apr 12, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    594
    TDAVISJR
    Apr 12, 2005
  3. Bob Rashkin
    Replies:
    5
    Views:
    100
    Dennis Lee Bieber
    Dec 23, 2013
  4. Steven D'Aprano
    Replies:
    0
    Views:
    143
    Steven D'Aprano
    Dec 23, 2013
  5. Replies:
    3
    Views:
    116
    Gary Herron
    Dec 23, 2013
Loading...

Share This Page