Adding a "Select" option to a databound dropdown

Discussion in 'ASP .Net' started by Simon Harvey, Jan 18, 2006.

  1. Simon Harvey

    Simon Harvey Guest

    Hi all,

    I have to use drop downs in a number of places in my applications. These
    drop downs are databound but I can't seem to see how to add a new item (eg
    "Select" or something like that) to the beginning of the drop down.

    I obviously dont want to have to put dodgy data like that in the database
    but I'm sure there is an easier solution.

    Can anyone help?

    Many thanks

    Simo
    Simon Harvey, Jan 18, 2006
    #1
    1. Advertising

  2. Simon,
    There are other ways, but what I usually do is just before setting the
    datasource, I add a DataRow with "Please Select" using DataTable.Rows.InsertAt
    Usually I cache stuff like this anyway so it only needs to be done once.
    Peter
    --
    Co-founder, Eggheadcafe.com developer portal:
    http://www.eggheadcafe.com
    UnBlog:
    http://petesbloggerama.blogspot.com




    "Simon Harvey" wrote:

    > Hi all,
    >
    > I have to use drop downs in a number of places in my applications. These
    > drop downs are databound but I can't seem to see how to add a new item (eg
    > "Select" or something like that) to the beginning of the drop down.
    >
    > I obviously dont want to have to put dodgy data like that in the database
    > but I'm sure there is an easier solution.
    >
    > Can anyone help?
    >
    > Many thanks
    >
    > Simon
    >
    >
    >
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Jan 18, 2006
    #2
    1. Advertising

  3. Try this:

    DropDownList1.Items.Insert(0, "Select <something>");

    You can also create a ListItem object and pass that in place of the string.
    --
    Christopher A. Reed
    "The oxen are slow, but the earth is patient."

    "Simon Harvey" <> wrote in message
    news:...
    > Hi all,
    >
    > I have to use drop downs in a number of places in my applications. These
    > drop downs are databound but I can't seem to see how to add a new item (eg
    > "Select" or something like that) to the beginning of the drop down.
    >
    > I obviously dont want to have to put dodgy data like that in the database
    > but I'm sure there is an easier solution.
    >
    > Can anyone help?
    >
    > Many thanks
    >
    > Simon
    >
    >
    Christopher Reed, Jan 18, 2006
    #3
    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. rodchar
    Replies:
    0
    Views:
    380
    rodchar
    Nov 26, 2007
  2. Manu
    Replies:
    0
    Views:
    159
  3. Bostonasian
    Replies:
    1
    Views:
    898
    Bostonasian
    Feb 14, 2005
  4. Monty
    Replies:
    2
    Views:
    142
  5. Replies:
    7
    Views:
    242
Loading...

Share This Page