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