coldchillin
asked on
Easy: Populate 2 Drop Down Lists with Date Ranges - Month, Year
I'm trying to populate these controls on page load. Month = 1-12, Year = Current Year + 20
<asp:DropDownList ID="lstMonth" runat="server"></asp:DropD ownList>
<asp:DropDownList ID="lstYear" runat="server"></asp:DropD ownList>
<asp:DropDownList ID="lstMonth" runat="server"></asp:DropD
<asp:DropDownList ID="lstYear" runat="server"></asp:DropD
protected void Page_Load(object sender, EventArgs e)
{
ArrayList arMonth = new ArrayList();
for (int i = 1; i < 13; i++)
{
arMonth.Add(i);
}
lstMonth.DataSource = arMonth;
lstMonth.DataBind();
lstMonth.Items.
}
or
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 1; i < 13; i++)
{
String iVal = System.Convert.ToString(i);
ListItem li = new ListItem();
li.Text = iVal;
li.Value = iVal;
lstMonth.Items.Add(li);
}
}
both didn't work
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
When I use:
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 1; i < 13; i++)
{
String iVal = System.Convert.ToString(i) ;
ListItem li = new ListItem();
li.Text = iVal;
li.Value = iVal;
lstMonth.Items.Add(li);
}
}
I have the box, and it has the appropriate length as if it was filled, but there are no displayed/clickable values...
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 1; i < 13; i++)
{
String iVal = System.Convert.ToString(i)
ListItem li = new ListItem();
li.Text = iVal;
li.Value = iVal;
lstMonth.Items.Add(li);
}
}
I have the box, and it has the appropriate length as if it was filled, but there are no displayed/clickable values...
ASKER
I also added the code from:
http://www.aspnettutorials.com/tutorials/controls/dropdownlist-binddate-csharp.aspx
and all my listboxes filled empty?! what's going on? I can statically set the listitem, that's the only way I'm getting this to populate...
http://www.aspnettutorials.com/tutorials/controls/dropdownlist-binddate-csharp.aspx
and all my listboxes filled empty?! what's going on? I can statically set the listitem, that's the only way I'm getting this to populate...
ASKER
Even this gives me nothing.
for (int i = 1; i < 13; i++)
{
lstMonth.Items.Add("yo");
}
Here is the .aspx code:
<asp:DropDownList ID="lstMonth" runat="server" ForeColor="#400000">
</asp:DropDownList>
what am i missing?!
for (int i = 1; i < 13; i++)
{
lstMonth.Items.Add("yo");
}
Here is the .aspx code:
<asp:DropDownList ID="lstMonth" runat="server" ForeColor="#400000">
</asp:DropDownList>
what am i missing?!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
<asp:DropDownList ID="lstMonth" runat="server"></asp:DropD