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

LVL 1
coldchillinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tempstf1Commented:
I just tested out your second method and it worked for me.. do not know what to tell you :s
0
coldchillinAuthor Commented:
Is this what your control looks like?

<asp:DropDownList ID="lstMonth" runat="server"></asp:DropDownList>
0
coldchillinAuthor Commented:
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...
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

coldchillinAuthor Commented:
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...
0
coldchillinAuthor Commented:
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?!
0
coldchillinAuthor Commented:
Here's what happened. The site is running a Master Page which was overriding everything in the Page Load event!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.