aspx页面上有三个DropDownList控件,
DropDownList1 表示年,DropDownList2表示月,DropDownList3表示天;
注意用将这三个DropDownList控件的AutoPostBack属性设为True。
用户可以方便地选择年月日,并且每月的日期会随着用户选择不同的年,月而发生相应的变化
其后台cs文件代码如下:
private void Page_Load(object sender, System.EventArgs e)
{
DateTime tnow=DateTime.Now;//现在时间
ArrayList AlYear=new ArrayList();
int i;
for(i=2002;i<=2010;i++)
AlYear.Add(i);
ArrayList AlMonth=new ArrayList();
for(i=1;i<=12;i++)
AlMonth.Add(i);
if(!this.IsPostBack )
{
DropDownList1.DataSource=AlYear;
DropDownList1.DataBind();//绑定年
//选择当前年
DropDownList1.SelectedV

本文介绍了如何在ASP.NET中使用三个DropDownList控件来方便地选择年月日。当用户切换年份或月份时,月份和日期会自动更新,确保显示正确的日期范围。代码示例展示了如何绑定数据源、判断闰年并根据所选年份和月份绑定天数。

441

被折叠的 条评论
为什么被折叠?



