Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two dropdownbox . I want that first one show the months and other one show the years . But they show according to Today's Date time . For example, for 2011 they show only nov and dec And for other years they show all months. The Years show in the years are upto 10 years.
Posted

1 solution

You can add years as
C#
for (int i = 0; i <= 9; i++) {
    ddl.Items.Add(DateAndTime.Now.Year + 1);
}


To add months, if the year is current year
C#
for (int i = DateAndTime.Now.Month; i <= 12; i++) {
    ddl.Items.Add(DateAndTime.MonthName(i));
}

else
C#
for (int i = 1; i <= 12; i++) {
    ddl.Items.Add(DateAndTime.MonthName(i));
}


You can consider CascadingDropDown to implement this.
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-Nov-11 2:24am    
Sure, a 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900