ASP.NET dropdownlist with 12 months and spanning multiple years

I am using ASP.NET, C#, and IE.

I need to create a dropdownlist box filled with 12 months. I know how to fill it with a straight 12 months, starting with January, all for the same year.  But what I want to do is fill the dropdown box with 12 months, starting with the current month, and going forward 9 months and having 3 months in the rear.  So, since the first month will be November, the list would start with August 2008 and have the next 12 months.  But since after 5 months, it will be 2009, the dropdown box will have to have month with 2008 and 2009.  Thanks in advance for the help.
geoffswebAsked:
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.

Anurag ThakurTechnical ManagerCommented:
on the page load fill in the months in your dropdown using following logic
                  DateTime dt = DateTime.Now.AddMonths(-3);
                  for (int i = 1; i < 13; i++)
                  {
                        Console.WriteLine(dt.ToString("MMM-yyyy"));
                        dt = dt.AddMonths(1);
                  }
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
the_bachelorCommented:
yo gotta load the dropdown dynamically.
One way of doing this is to write a method similar to whats shown below and call it in the Page Load
 Sub LoadDates()
        Dim textToDisplay As String
        Dim startDate As Date = Now.AddMonths(-3)
        For i = 0 To 11
            textToDisplay = startDate.AddMonths(i).ToString("MMMM yyyy")
            Me.DropDownList1.Items.Add(textToDisplay)
        Next
    End Sub

Open in new window

0
the_bachelorCommented:
Oops I was a little behind ragi. But as you can see, same concept.
0
geoffswebAuthor Commented:
PERFECT !
0
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
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.