在ASP.NET中用三个DropDownList控件方便的选择年月日【原创】

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

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.SelectedValue=tnow.Year.ToString();
      DropDownList2.DataSource=AlMonth;
      DropDownList2.DataBind();

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值