如何在下拉列表中显示月份和年份 [英] How to show the month and year in dropdownlist

查看:232
本文介绍了如何在下拉列表中显示月份和年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个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[^]


这篇关于如何在下拉列表中显示月份和年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆