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. dropdown

dropdown

Scheduled Pinned Locked Moved ASP.NET
databasehelptutorialquestion
7 Posts 5 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.
  • A Offline
    A Offline
    arkiboys
    wrote on last edited by
    #1

    I have populated a dropdown control. The items inside the dropdown are: "hello", "you", "there" based on a few retrieved items from the database, I would like the correct item in the dropdown to be selected. For example: string strValue = "you"; ddlgvSources.selectedItem.Text = strValue; The problem here is that the text in strValue over writes the value inside the dropdown, so when I click on the dropdown to see all the items, it shows: you you there Do you know why? Thanks

    J D 2 Replies Last reply
    0
    • A arkiboys

      I have populated a dropdown control. The items inside the dropdown are: "hello", "you", "there" based on a few retrieved items from the database, I would like the correct item in the dropdown to be selected. For example: string strValue = "you"; ddlgvSources.selectedItem.Text = strValue; The problem here is that the text in strValue over writes the value inside the dropdown, so when I click on the dropdown to see all the items, it shows: you you there Do you know why? Thanks

      J Offline
      J Offline
      J a a n s
      wrote on last edited by
      #2

      You are trying to replace the text instead of selecting the required one. You have to find the correct list item using the method FindItemByText or FindItemByValue of DropDownand then Select it.

      ListItem item;
      ddl.SelectedIndex = -1;
      item = ddl.Items.FindByText("hello");
      if (item != null) item.Selected = true;

      S A 2 Replies Last reply
      0
      • J J a a n s

        You are trying to replace the text instead of selecting the required one. You have to find the correct list item using the method FindItemByText or FindItemByValue of DropDownand then Select it.

        ListItem item;
        ddl.SelectedIndex = -1;
        item = ddl.Items.FindByText("hello");
        if (item != null) item.Selected = true;

        S Offline
        S Offline
        Shivendra Pandey
        wrote on last edited by
        #3

        ListItem item=DropDownList1.Items[DropDownList1.SelectedIndex]; DropDownList1.Items.Remove(item); DropDownList1.Items.Insert(0, item);

        N 1 Reply Last reply
        0
        • S Shivendra Pandey

          ListItem item=DropDownList1.Items[DropDownList1.SelectedIndex]; DropDownList1.Items.Remove(item); DropDownList1.Items.Insert(0, item);

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          And how does this solved the OPs problem?


          I know the language. I've read a book. - _Madmatt

          1 Reply Last reply
          0
          • J J a a n s

            You are trying to replace the text instead of selecting the required one. You have to find the correct list item using the method FindItemByText or FindItemByValue of DropDownand then Select it.

            ListItem item;
            ddl.SelectedIndex = -1;
            item = ddl.Items.FindByText("hello");
            if (item != null) item.Selected = true;

            A Offline
            A Offline
            arkiboys
            wrote on last edited by
            #5

            Thanks

            1 Reply Last reply
            0
            • A arkiboys

              I have populated a dropdown control. The items inside the dropdown are: "hello", "you", "there" based on a few retrieved items from the database, I would like the correct item in the dropdown to be selected. For example: string strValue = "you"; ddlgvSources.selectedItem.Text = strValue; The problem here is that the text in strValue over writes the value inside the dropdown, so when I click on the dropdown to see all the items, it shows: you you there Do you know why? Thanks

              D Offline
              D Offline
              DJ Matthews
              wrote on last edited by
              #6

              Try this:

              ddlgvSources.SelectedValue = strValue;

              A 1 Reply Last reply
              0
              • D DJ Matthews

                Try this:

                ddlgvSources.SelectedValue = strValue;

                A Offline
                A Offline
                arkiboys
                wrote on last edited by
                #7

                thank you

                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