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. Selected index opf dropdown within a repeater always returns 0

Selected index opf dropdown within a repeater always returns 0

Scheduled Pinned Locked Moved ASP.NET
databasedata-structuresquestion
4 Posts 2 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.
  • O Offline
    O Offline
    oceanexplorer
    wrote on last edited by
    #1

    Hi, I currently have a repeater that renders a series of dropdowns depending on data returned from the database. When the user clicks next on the screen I want to cycle through the dropdowns in the repeater and stored the selectedindex of each into an array that will then be stored in session. So that if the user returns the values they selected will persist. The code I have is a follows: int[] intArray = new int[RemapRepeater.Items.Count]; DropDownList reMapDropDown = new DropDownList(); for (int i=1; i <= RemapRepeater.Items.Count; i++) { reMapDropDown = (DropDownList)RemapRepeater.Controls[i].FindControl("reMapDropDown"); intArray[i] = reMapDropDown.SelectedIndex; } However every dropdown returns a selected value of 0, as if it's picking up the values of the page when it was first rendered and not the values that have been selected. Has anyone any ideas where I might be going wrong? Regards Paul Custance

    C 1 Reply Last reply
    0
    • O oceanexplorer

      Hi, I currently have a repeater that renders a series of dropdowns depending on data returned from the database. When the user clicks next on the screen I want to cycle through the dropdowns in the repeater and stored the selectedindex of each into an array that will then be stored in session. So that if the user returns the values they selected will persist. The code I have is a follows: int[] intArray = new int[RemapRepeater.Items.Count]; DropDownList reMapDropDown = new DropDownList(); for (int i=1; i <= RemapRepeater.Items.Count; i++) { reMapDropDown = (DropDownList)RemapRepeater.Controls[i].FindControl("reMapDropDown"); intArray[i] = reMapDropDown.SelectedIndex; } However every dropdown returns a selected value of 0, as if it's picking up the values of the page when it was first rendered and not the values that have been selected. Has anyone any ideas where I might be going wrong? Regards Paul Custance

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

      If your drop down is data bound and you bind to the data source every time, that will reset the selected index. Use !IsPostback to only do it the first time.

      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 )

      O 1 Reply Last reply
      0
      • C Christian Graus

        If your drop down is data bound and you bind to the data source every time, that will reset the selected index. Use !IsPostback to only do it the first time.

        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 )

        O Offline
        O Offline
        oceanexplorer
        wrote on last edited by
        #3

        OK, I truly hang my head in shame, how could I miss something so obvious! Think I couldn't see the wood for the trees, so to speak! Thanks Christian, worked a treat and thanks for such a prompt response :) Paul

        C 1 Reply Last reply
        0
        • O oceanexplorer

          OK, I truly hang my head in shame, how could I miss something so obvious! Think I couldn't see the wood for the trees, so to speak! Thanks Christian, worked a treat and thanks for such a prompt response :) Paul

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

          Glad to help :-)

          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