如何在下拉列表中显示月份和年份

问题描述:

我有两个dropdownbox.我要第一个显示月份,而另一个显示年份.但是它们根据今天的日期时间显示.例如,对于2011年,它们仅显示nov和dec;对于其他年份,它们仅显示所有月份.年份中的年份最多为10年.

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.

您可以将年份添加为
You can add years as
for (int i = 0; i <= 9; i++) {
    ddl.Items.Add(DateAndTime.Now.Year + 1);
}



要添加月份(如果年份是当前年份)



To add months, if the year is current year

for (int i = DateAndTime.Now.Month; i <= 12; i++) {
    ddl.Items.Add(DateAndTime.MonthName(i));
}


其他


else

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



您可以考虑使用CascadingDropDown来实现.
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx [ ^ ]



You can consider CascadingDropDown to implement this.
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx[^]