Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Creating a drop down list (databounded) and adding a "Please Select"

Creating a drop down list (databounded) and adding a "Please Select"

Scheduled Pinned Locked Moved ASP.NET
question
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Desmond Lim
    wrote on last edited by
    #1

    Hi, I'm wondering if this can be done. I have a drop down list that I populate with data from a table. I'd like to add a "Please Select" to the drop down list and make it the first item on the list, so that when the page is loaded, the user will see "Please Select" instead of "amp" in the drop down list. Can this be done? If so how? Thanks. Desmond

    C G T 3 Replies Last reply
    0
    • D Desmond Lim

      Hi, I'm wondering if this can be done. I have a drop down list that I populate with data from a table. I'd like to add a "Please Select" to the drop down list and make it the first item on the list, so that when the page is loaded, the user will see "Please Select" instead of "amp" in the drop down list. Can this be done? If so how? Thanks. Desmond

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You need to add 'please select' to your data source before binding, as once you bind, you cannot add other items.

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      1 Reply Last reply
      0
      • D Desmond Lim

        Hi, I'm wondering if this can be done. I have a drop down list that I populate with data from a table. I'd like to add a "Please Select" to the drop down list and make it the first item on the list, so that when the page is loaded, the user will see "Please Select" instead of "amp" in the drop down list. Can this be done? If so how? Thanks. Desmond

        G Offline
        G Offline
        Gayani Devapriya
        wrote on last edited by
        #3

        Hi, Yes its possible. Have a look at this sample. DropDownList1.Items.Add(new ListItem("aaa", "1")); DropDownList1.Items.Add(new ListItem("bbb", "2")); DropDownList1.Items.Insert(0, new ListItem("-- Please Select --")); Items.Add() method adds the items to the Dropdown. Over here you may bind the items from the table, thats fine. Then use the Items.Insert() method specifing the index (here it's 0 which will be the first item in your drop down) and give the ListItem ("Please select" text) as the item to be added. Thx Gayani

        C 1 Reply Last reply
        0
        • G Gayani Devapriya

          Hi, Yes its possible. Have a look at this sample. DropDownList1.Items.Add(new ListItem("aaa", "1")); DropDownList1.Items.Add(new ListItem("bbb", "2")); DropDownList1.Items.Insert(0, new ListItem("-- Please Select --")); Items.Add() method adds the items to the Dropdown. Over here you may bind the items from the table, thats fine. Then use the Items.Insert() method specifing the index (here it's 0 which will be the first item in your drop down) and give the ListItem ("Please select" text) as the item to be added. Thx Gayani

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Gayani Devapriya wrote:

          Over here you may bind the items from the table, thats fine. Then use the Items.Insert() method specifing the index (here it's 0 which will be the first item in your drop down) and give the ListItem ("Please select" text) as the item to be added.

          No, if a control is data bound, you cannot add items to it using code.

          Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          1 Reply Last reply
          0
          • D Desmond Lim

            Hi, I'm wondering if this can be done. I have a drop down list that I populate with data from a table. I'd like to add a "Please Select" to the drop down list and make it the first item on the list, so that when the page is loaded, the user will see "Please Select" instead of "amp" in the drop down list. Can this be done? If so how? Thanks. Desmond

            T Offline
            T Offline
            TheWirelessGuy
            wrote on last edited by
            #5

            In the properties of the drop down list control, set the AppendDataBoundItems to true. Then, in the Items Collection, add the item "Please Select". Finally, bind the list as you are now. The control will first insert any items that are in the "Items Collection", then it will (as the property states) append the data bound items to the control.

            Steve

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups