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. add list items to dropdowlist [modified]

add list items to dropdowlist [modified]

Scheduled Pinned Locked Moved ASP.NET
questionhelp
9 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.
  • P Offline
    P Offline
    playout
    wrote on last edited by
    #1

    Hi, I have a dropdownlist that gets populated programmatically from a datasource. However, depending if the user is a admin user, I want to add 2 more list items to the Here is my code on how I add the list items programmatically to that list: drpStatus.Items.Add("Admin") drpStatus.Items.Add("Global") Problem with my code is, the value and display of the list item is the same. My value and display text differ. I need to have something like(excuse the code, but it does not render correctly when posted: How can I do this?

    _ P 2 Replies Last reply
    0
    • P playout

      Hi, I have a dropdownlist that gets populated programmatically from a datasource. However, depending if the user is a admin user, I want to add 2 more list items to the Here is my code on how I add the list items programmatically to that list: drpStatus.Items.Add("Admin") drpStatus.Items.Add("Global") Problem with my code is, the value and display of the list item is the same. My value and display text differ. I need to have something like(excuse the code, but it does not render correctly when posted: How can I do this?

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

      playout wrote:

      something like:

      Something like what? If you are using html tags then check the box "ignore HTML tags in this message (good for code snippets)"

      Best Regards, Apurva Kaushal

      P 1 Reply Last reply
      0
      • _ _AK_

        playout wrote:

        something like:

        Something like what? If you are using html tags then check the box "ignore HTML tags in this message (good for code snippets)"

        Best Regards, Apurva Kaushal

        P Offline
        P Offline
        playout
        wrote on last edited by
        #3

        Hi, I changed my message. Thanks for the tip on the tags!

        _ S 2 Replies Last reply
        0
        • P playout

          Hi, I changed my message. Thanks for the tip on the tags!

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

          you can do it like this: ListItem li = new ListItem("test3,t); ddl.Items.Add(li);

          Best Regards, Apurva Kaushal

          P 1 Reply Last reply
          0
          • P playout

            Hi, I changed my message. Thanks for the tip on the tags!

            S Offline
            S Offline
            Sandeep Akhare
            wrote on last edited by
            #5

            OK i think you want to add value also if i am not wrong try this ListItem items = new ListItem("Admin", "A"); or you can do this way also ListItem items = new ListItem(); items.Text = "Global"; items.Value = "G"; Add to the DropDownList DropDownList1.Items.Add(items); Is it fine ? Send your reply

            P 1 Reply Last reply
            0
            • _ _AK_

              you can do it like this: ListItem li = new ListItem("test3,t); ddl.Items.Add(li);

              Best Regards, Apurva Kaushal

              P Offline
              P Offline
              playout
              wrote on last edited by
              #6

              Thanks Apurva, I got it to work.

              _ 1 Reply Last reply
              0
              • S Sandeep Akhare

                OK i think you want to add value also if i am not wrong try this ListItem items = new ListItem("Admin", "A"); or you can do this way also ListItem items = new ListItem(); items.Text = "Global"; items.Value = "G"; Add to the DropDownList DropDownList1.Items.Add(items); Is it fine ? Send your reply

                P Offline
                P Offline
                playout
                wrote on last edited by
                #7

                Hi, Yes, thank you, this worked too. Thanks for the help.

                1 Reply Last reply
                0
                • P playout

                  Thanks Apurva, I got it to work.

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

                  always welcome.. :)

                  Best Regards, Apurva Kaushal

                  1 Reply Last reply
                  0
                  • P playout

                    Hi, I have a dropdownlist that gets populated programmatically from a datasource. However, depending if the user is a admin user, I want to add 2 more list items to the Here is my code on how I add the list items programmatically to that list: drpStatus.Items.Add("Admin") drpStatus.Items.Add("Global") Problem with my code is, the value and display of the list item is the same. My value and display text differ. I need to have something like(excuse the code, but it does not render correctly when posted: How can I do this?

                    P Offline
                    P Offline
                    P A N K A J
                    wrote on last edited by
                    #9

                    You can use this one line code DropDownList1.Items.Add(new ListItem("test","t"));

                    Pankaj Gupta (Take it easy)

                    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