drop down menu - asp.net DropDownList in sync -


I have three dropdowns to select one year under user control I specify the value selected for a drop down on load. The other two drop-downs are automatically assigned to the same selected value. No matter whether the dropdown is allocated to any selected value, all three of them get the same selected value. I've tried to create a new user control for the dropdown, but it does.

  & lt;% @ Control language = "C #" AutoEventWireup = "true" CodeBehind = "DropDownTest.ascx CS" Inheritance = "Weimann Management. DropdownTest"% & gt; & Lt; P & gt; & Lt; Asp: dropdown list id = "ddlStartDateYear" runat = "server" & gt; & Lt; / ASP: DropDownList & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Asp: dropdown list id = "ddlEndDateYear" runat = "server" & gt; & Lt; / ASP: DropDownList & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Asp: dropdown list id = "year" run = "server" & gt; & Lt; / Asp: dropdown list & gt; & Lt; / P & gt;  

Code Back:

  Using the system; Using System.Collections.Generic; Using System.Linq; Using System.Web; Using System.Web.UI; Using System.Web.UI.WebControls; Namespace WymanOrgManagement {Public Partial Category DropDownTest: System.Web.UI.UserControl {Secure Zero Page_load (Object Sender, EventArgs e) {populateDatesAndStates (); DdlEndDateYear.SelectedIndex = 2; } Protected zero populators and status () {ListItem init2 = new ListItem (); Init2.Text = init2.Value = "year ..."; DdlStartDateYear.Items.Add (init2); DdlEndDateYear.Items.Add (init2); Year.Items.Add (init2); For (Int i = datetime. Now.Year - 1; i  

All three dropdowns are similar to ListItem . When you set it to selected in one place, it is selected in all 3 locations.

  ListItem item = new ListItem (); Item.Text = item.Value = i.ToString (); DdlStartDateYear.Items.Add (item); DdlEndDateYear.Items.Add (item); Year.Items.Add (item);  

You probably want to do this

  ddlStartDateYear.Items.Add (i.ToString ()); DdlEndDateYear.Items.Add (i.ToString ()); Year. ITEM Add (i.ToString ());  

This will make a new instance of ListItem (similar values) to go to each list.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -