I have three dropdowns for selecting a year inside a user control. On load I specify the selected value for one drop down. The other two drop downs are automatically getting assigned the same selected value. No matter which dropdown I assign a selected value to, they all three get the same selected value. I've tried recreating a new user control for the dropdowns but the same thing happens.
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DropDownTest.ascx.cs" Inherits="WymanOrgManagement.DropDownTest" %>
<p>
<asp:DropDownList ID="ddlStartDateYear" runat="server">
</asp:DropDownList>
</p>
<p>
<asp:DropDownList ID="ddlEndDateYear" runat="server">
</asp:DropDownList>
</p>
<p>
<asp:DropDownList ID="Year" runat="server"></asp:DropDownList>
</p>
Code Behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WymanOrgManagement
{
public partial class DropDownTest : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
populateDatesAndStates();
ddlEndDateYear.SelectedIndex = 2;
}
protected void populateDatesAndStates()
{
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 < DateTime.Now.Year + 10; i++)
{
ListItem item = new ListItem();
item.Text = item.Value = i.ToString();
ddlStartDateYear.Items.Add(item); ddlEndDateYear.Items.Add(item);
Year.Items.Add(item);
}
}
}
}
Can someone help me figure out why the three dropdowns seem to be in sync? Thanks!