Link to home
Start Free TrialLog in
Avatar of coldchillin
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:DropDownList>
<asp:DropDownList ID="lstYear" runat="server"></asp:DropDownList>

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

Open in new window

SOLUTION
Avatar of tempstf1
tempstf1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of coldchillin
coldchillin

ASKER

Is this what your control looks like?

<asp:DropDownList ID="lstMonth" runat="server"></asp:DropDownList>
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...
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...
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?!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial