ASP.NET中实现日期下拉框(用类实现)

 DropDownList1是月,DropDownList2是年,DropDownList3是日。
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
int i;
ArrayList month=new ArrayList();
for(i=1;i<=12;i++)
num.Add(i);
this.DropDownList1.DataSource=month;
this.DropDownList1.DataBind();
//以上初始化月
int j;
ArrayList year=new ArrayList();
for(j=2000;j<=2020;j++)
year.Add(j);
this.DropDownList2.DataSource=year;
this.DropDownList2.DataBind();
//以上初始化年
this.DropDownList1.AutoPostBack=true;
this.DropDownList2.AutoPostBack=true;
}
}

private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
day(this.DropDownList1.SelectedValue,Convert.ToInt16(this.DropDownList2.SelectedValue));
}

private void day(string d,int year)
{
switch(d)
{
case "1":
case "3":
case "5":
case "7":
case "8":
case "10":
case "12":
daynum("31");
break;
case "2":
if((year%4==0&&year%100!=0)||(year%400==0))
daynum("29");
else
daynum("28");
break;
default:
daynum("30");
break;
}

}

private void daynum(string num)
{
int i;
ArrayList day=new ArrayList();
for(i=1;i<=Convert.ToInt16(num);i++)
day.Add(i);
this.DropDownList3.DataSource=day;
this.DropDownList3.DataBind();
}

private void DropDownList2_SelectedIndexChanged(object sender, System.EventArgs e)
{
day(this.DropDownList1.SelectedValue,Convert.ToInt16(this.DropDownList2.SelectedValue));
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值