I am new to C # since I mainly used Java.
But straight to the problem (which I simplified a bit):
First excerpt of my aspx page:
<div class="dates">
<div class="firstselection">
<asp:DropDownList ID="DDFromMonth" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="DDToMonth" runat="server">
</asp:DropDownList>
</div>
</div>
And codebehind:
public partial class Argh: System.Web.UI.Page
{
static List<ListItem> monthList = new List<ListItem>
{
new ListItem("Jan", "1"),
new ListItem("Feb", "2"),
new ListItem("Mar", "3"),
new ListItem("Apr", "4"),
new ListItem("May", "5"),
new ListItem("Jun", "6"),
new ListItem("Jul", "7"),
new ListItem("Aug", "8"),
new ListItem("Sep", "9"),
new ListItem("Oct", "10"),
new ListItem("Nov", "11"),
new ListItem("Dec", "12")
};
protected void Page_Load(object sender, EventArgs e)
{
DDFromMonth.Items.AddRange(monthList.ToArray());
DDToMonth.Items.AddRange(monthList.ToArray());
DDFromMonth.SelectedValue = "6";
DDToMonth.SelectedValue = "7";
}
Ok, I have a static list containing months. I am adding a range to this list for both the dropdown menu and DDFromMonth. I select "6" (June) and DDToMonth "7" (July). However, this leads to both dropdownlists showing July!
I also tried using a non-static list, but that doesn't matter. The only thing I tested, "works", is to create two different lists - only then the drop-down lists are selected as you wish. So, adding lists like this does the job (but ugly):
DDFromMonth.Items.AddRange(monthList.ToArray());
DDFromMonth.Items.AddRange(aDuplicatedMonthList.ToArray());
, asp.net, , , , . . , ? , -, -, # ASP.NET