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. Dropdownlist set without SelecteIndex Property...

Dropdownlist set without SelecteIndex Property...

Scheduled Pinned Locked Moved ASP.NET
help
7 Posts 3 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
    Amit Kumar G
    wrote on last edited by
    #1

    How i can set the dropdownlist without using Selectindex property. Because in my repeater control (where i am displaying dropdownlist data) , i don't have assoicated listindex values, i just have dropdown list text. I tried to use ((DropDownList)(FormView1.FindControl("CmbCountry"))).Text= "USA"; and i got erroe as below has a SelectedValue which is invalid because it does not exist in the list of items. Please help...

    C M 2 Replies Last reply
    0
    • A Amit Kumar G

      How i can set the dropdownlist without using Selectindex property. Because in my repeater control (where i am displaying dropdownlist data) , i don't have assoicated listindex values, i just have dropdown list text. I tried to use ((DropDownList)(FormView1.FindControl("CmbCountry"))).Text= "USA"; and i got erroe as below has a SelectedValue which is invalid because it does not exist in the list of items. Please help...

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

      Amit Kumar G wrote:

      has a SelectedValue which is invalid because it does not exist in the list of items.

      OK, so you're on the right track, but the text you tried to set does not appear in the list. Therefore, if you use a string that does appear in the list, this is the right way to set the value by text instead of index. Isn't there also a findindex method ? Or you can iterate over the Items collection to find the one you want, to ensure it is there.

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      1 Reply Last reply
      0
      • A Amit Kumar G

        How i can set the dropdownlist without using Selectindex property. Because in my repeater control (where i am displaying dropdownlist data) , i don't have assoicated listindex values, i just have dropdown list text. I tried to use ((DropDownList)(FormView1.FindControl("CmbCountry"))).Text= "USA"; and i got erroe as below has a SelectedValue which is invalid because it does not exist in the list of items. Please help...

        M Offline
        M Offline
        mr mohsen
        wrote on last edited by
        #3

        oh dont worry... its easy just set dropdownlist_name.SelectedValue="USA" now test it and enjoy... msma www.toolsfa.com

        A 1 Reply Last reply
        0
        • M mr mohsen

          oh dont worry... its easy just set dropdownlist_name.SelectedValue="USA" now test it and enjoy... msma www.toolsfa.com

          A Offline
          A Offline
          Amit Kumar G
          wrote on last edited by
          #4

          Dear Mohsen, It is giving the same error CmbCountry' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value when i am doing ((DropDownList)(FormView1.FindControl("CmbCountry"))).SelectedValue = "USA";

          M A 2 Replies Last reply
          0
          • A Amit Kumar G

            Dear Mohsen, It is giving the same error CmbCountry' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value when i am doing ((DropDownList)(FormView1.FindControl("CmbCountry"))).SelectedValue = "USA";

            M Offline
            M Offline
            mr mohsen
            wrote on last edited by
            #5

            test this code: for (int i = 0; i < [your repeater].Rows.Count; i++) { Control ctrl = gv_links_edit.Rows[i].Cells[0].FindControl("[your item name]"); DropDownList ddl= (DropDownList)ctrl; ddl.SelectedValue="USA"; } i use this code and i dont have any problem. good luck msma. www.toolsfa.com

            1 Reply Last reply
            0
            • A Amit Kumar G

              Dear Mohsen, It is giving the same error CmbCountry' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value when i am doing ((DropDownList)(FormView1.FindControl("CmbCountry"))).SelectedValue = "USA";

              A Offline
              A Offline
              Amit Kumar G
              wrote on last edited by
              #6

              Solved, In case some one is having similar probs. var lb = document.getElementById("FormView1_CmbCountry"); for(var i=0;i

              C 1 Reply Last reply
              0
              • A Amit Kumar G

                Solved, In case some one is having similar probs. var lb = document.getElementById("FormView1_CmbCountry"); for(var i=0;i

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

                This works ? It looks like javascript to me, and I thought the selected property could only be true or false ?

                Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                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