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. drop down

drop down

Scheduled Pinned Locked Moved ASP.NET
6 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.
  • F Offline
    F Offline
    fmardani
    wrote on last edited by
    #1

    Hi, A drop down list is populated using datasource as below ddlUsers.DataSource = Membership.GetAllUsers ddlUsers.DataBind() But now I want the drop down to show the following item as the first item. If I just use the following line, it gets added to the last item in the list. ddlUsers.Items.Add("<-- select a user -->") Thanks

    G R _ 3 Replies Last reply
    0
    • F fmardani

      Hi, A drop down list is populated using datasource as below ddlUsers.DataSource = Membership.GetAllUsers ddlUsers.DataBind() But now I want the drop down to show the following item as the first item. If I just use the following line, it gets added to the last item in the list. ddlUsers.Items.Add("<-- select a user -->") Thanks

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Use the Insert method to specify where the item should be added:

      ddlUsers.Items.Insert(0, "<-- select a user -->")

      --- b { font-weight: normal; }

      1 Reply Last reply
      0
      • F fmardani

        Hi, A drop down list is populated using datasource as below ddlUsers.DataSource = Membership.GetAllUsers ddlUsers.DataBind() But now I want the drop down to show the following item as the first item. If I just use the following line, it gets added to the last item in the list. ddlUsers.Items.Add("<-- select a user -->") Thanks

        R Offline
        R Offline
        R Prabha Devi
        wrote on last edited by
        #3

        Hi, Before binding value to the dropdown write the below code,

        ddlUsers.Items.Clear();
        newListItem = new ListItem();
        newListItem.Value = "----Select a user---";
        newListItem.Text = "----Select a user----";
        ddlUsers.Items.Add(newListItem);

        ddlUsers.DataSource = Membership.GetAllUsers
        ddlUsers.DataBind()

        Hope this helps u .. :)

        F 1 Reply Last reply
        0
        • F fmardani

          Hi, A drop down list is populated using datasource as below ddlUsers.DataSource = Membership.GetAllUsers ddlUsers.DataBind() But now I want the drop down to show the following item as the first item. If I just use the following line, it gets added to the last item in the list. ddlUsers.Items.Add("<-- select a user -->") Thanks

          _ Offline
          _ Offline
          _AK_
          wrote on last edited by
          #4

          hi, You can add this line to get the desired result. ddlUsers.Items.Insert(0,new ListItem("-- select a user --","0")); Hope this will solve your problem.:) Best Regards, Apurva Kaushal

          F 1 Reply Last reply
          0
          • R R Prabha Devi

            Hi, Before binding value to the dropdown write the below code,

            ddlUsers.Items.Clear();
            newListItem = new ListItem();
            newListItem.Value = "----Select a user---";
            newListItem.Text = "----Select a user----";
            ddlUsers.Items.Add(newListItem);

            ddlUsers.DataSource = Membership.GetAllUsers
            ddlUsers.DataBind()

            Hope this helps u .. :)

            F Offline
            F Offline
            fmardani
            wrote on last edited by
            #5

            Hi, This will not work because "----Select a user----" will not be shown. Try it and see. Thanks

            1 Reply Last reply
            0
            • _ _AK_

              hi, You can add this line to get the desired result. ddlUsers.Items.Insert(0,new ListItem("-- select a user --","0")); Hope this will solve your problem.:) Best Regards, Apurva Kaushal

              F Offline
              F Offline
              fmardani
              wrote on last edited by
              #6

              It seems that insert is the solution. Thanks guys

              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