含氨基酸的洗发水:ASP.NET中如何实现日期下拉框呀?

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 04:42:53

我的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));
}