?
Solved

ASP.NET dropdownlist with 12 months and spanning multiple years

Posted on 2008-11-03
4
Medium Priority
?
623 Views
Last Modified: 2008-11-03
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.
0
Comment
Question by:geoffsweb
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 252 total points
ID: 22868826
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
 
LVL 7

Assisted Solution

by:the_bachelor
the_bachelor earned 248 total points
ID: 22868848
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
 
LVL 7

Expert Comment

by:the_bachelor
ID: 22868860
Oops I was a little behind ragi. But as you can see, same concept.
0
 

Author Comment

by:geoffsweb
ID: 22869894
PERFECT !
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question