How do i: Databinding 2 database columns to a single dropdown control

Discussion in 'ASP .Net' started by John Blair, Dec 28, 2004.

  1. John Blair

    John Blair Guest

    Hi,

    I want to select an id column and a name column from the database
    and have the results databound to a SINGLE dropdown control with the value
    property matched to the database id column and the name values on
    display to the user. Any idea how i can do this?

    Sample HTML showing desired result: Thanks for any help!

    <select name="DropDown1" id="DropDown1">
    <option value="1">IN</option>
    <option value="2">KS</option>
    <option value="3">MD</option>
    <option value="4">MI</option>
    <option value="5">OR</option>
    <option value="6">TN</option>

    </select>
     
    John Blair, Dec 28, 2004
    #1
    1. Advertising

  2. If you get the data into a dataset DSStates with a table tblStates, then
    the dropdownlist will look like the following:

    <asp:dropdownlist id=ddlLocation Runat="server" DataTextField="Name" DataValueField="Id"
    DataMember="tblStates" DataSource="<%# DSStates %>"></asp:dropdownlist>

    Eliyahu

    > Hi,
    >
    > I want to select an id column and a name column from the database
    > and have the results databound to a SINGLE dropdown control with the
    > value
    > property matched to the database id column and the name values on
    > display to the user. Any idea how i can do this?
    > Sample HTML showing desired result: Thanks for any help!
    >
    > <select name="DropDown1" id="DropDown1">
    > <option value="1">IN</option>
    > <option value="2">KS</option>
    > <option value="3">MD</option>
    > <option value="4">MI</option>
    > <option value="5">OR</option>
    > <option value="6">TN</option>
    > </select>
    >
     
    Eliyahu Goldin, Dec 28, 2004
    #2
    1. Advertising

  3. John Blair

    John Blair Guest

    Thanks alot....right again!!!!!!
    I wanted the intial selection to be nothing .listindex=-1 in vb terms but it
    always seems to select first item even if i reset listindex to -1 after
    databinding.
    HAve i got to load a blank entry as the first item in the dropdownlist?

    Thanks a lot!

    "Eliyahu Goldin" <> wrote in message
    news:...
    > If you get the data into a dataset DSStates with a table tblStates, then
    > the dropdownlist will look like the following:
    >
    > <asp:dropdownlist id=ddlLocation Runat="server" DataTextField="Name"
    > DataValueField="Id" DataMember="tblStates" DataSource="<%# DSStates
    > %>"></asp:dropdownlist>
    >
    > Eliyahu
    >
    >> Hi,
    >>
    >> I want to select an id column and a name column from the database
    >> and have the results databound to a SINGLE dropdown control with the
    >> value
    >> property matched to the database id column and the name values on
    >> display to the user. Any idea how i can do this?
    >> Sample HTML showing desired result: Thanks for any help!
    >>
    >> <select name="DropDown1" id="DropDown1">
    >> <option value="1">IN</option>
    >> <option value="2">KS</option>
    >> <option value="3">MD</option>
    >> <option value="4">MI</option>
    >> <option value="5">OR</option>
    >> <option value="6">TN</option>
    >> </select>
    >>

    >
    >
     
    John Blair, Dec 28, 2004
    #3
  4. John Blair

    John Blair Guest

    Hi,

    I found this code snipet to do the trick after data binding!

    DropDownList1.Items.Insert(0, New ListItem("", "-1"))



    Thanks!

    "John Blair" <> wrote in message
    news:VfgAd.111$...
    > Thanks alot....right again!!!!!!
    > I wanted the intial selection to be nothing .listindex=-1 in vb terms but
    > it always seems to select first item even if i reset listindex to -1 after
    > databinding.
    > HAve i got to load a blank entry as the first item in the dropdownlist?
    >
    > Thanks a lot!
    >
    > "Eliyahu Goldin" <> wrote in message
    > news:...
    >> If you get the data into a dataset DSStates with a table tblStates, then
    >> the dropdownlist will look like the following:
    >>
    >> <asp:dropdownlist id=ddlLocation Runat="server" DataTextField="Name"
    >> DataValueField="Id" DataMember="tblStates" DataSource="<%# DSStates
    >> %>"></asp:dropdownlist>
    >>
    >> Eliyahu
    >>
    >>> Hi,
    >>>
    >>> I want to select an id column and a name column from the database
    >>> and have the results databound to a SINGLE dropdown control with the
    >>> value
    >>> property matched to the database id column and the name values on
    >>> display to the user. Any idea how i can do this?
    >>> Sample HTML showing desired result: Thanks for any help!
    >>>
    >>> <select name="DropDown1" id="DropDown1">
    >>> <option value="1">IN</option>
    >>> <option value="2">KS</option>
    >>> <option value="3">MD</option>
    >>> <option value="4">MI</option>
    >>> <option value="5">OR</option>
    >>> <option value="6">TN</option>
    >>> </select>
    >>>

    >>
    >>

    >
    >
     
    John Blair, Dec 28, 2004
    #4
    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. Neel

    Databinding issue with dropdown

    Neel, Oct 22, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    318
  2. Replies:
    5
    Views:
    630
  3. jobs
    Replies:
    0
    Views:
    1,764
  4. Replies:
    2
    Views:
    459
  5. Earl Teigrob
    Replies:
    1
    Views:
    444
    Shravan
    Mar 1, 2004
Loading...

Share This Page