dropdownlist 显示日期

dropdownlist1代表年 autopostback=true

dropdownlist2代表月 autopostback=true

dropdownlist3代表日


protected void Page_Load( object sender,EventArgse)
... {
strings=Request.QueryString["id"];
Response.Write(Server.UrlDecode(s));

DateTimetnow
=DateTime.Now;
ArrayListyears
=newArrayList();
ArrayListmonths
=newArrayList();
inti;
for(i=1991;i>=1958;i--)
...{
years.Add(i);
}

for(i=1;i<=12;i++)
...{
months.Add(i);
}


if(!IsPostBack)
...{
DropDownList1.DataSource
=years;
DropDownList1.SelectedValue
=years[8].ToString();
DropDownList1.DataBind();

DropDownList2.DataSource
=months;
DropDownList2.SelectedValue
=tnow.Month.ToString();
DropDownList2.DataBind();

intyear,month;
Int32.TryParse(tnow.Year.ToString(),
outyear);
Int32.TryParse(tnow.Month.ToString(),
outmonth);

binddropdownlist3(year,month);
DropDownList3.SelectedValue
=tnow.Day.ToString();
}

}


protected bool checkLeap( int year)
... {
if((year%4!=0)&&(year%100!=0)||(year%400==0))
...{
returntrue;
}

else
...{
returnfalse;
}

}


protected void binddropdownlist3( int year, int month)
... {
inti;
ArrayListdays
=newArrayList();
switch(month)
...{
case1:
case3:
case5:
case7:
case8:
case10:
case12:
for(i=1;i<=31;i++)
...{
days.Add(i);
}

break;
case2:
if(checkLeap(year))
...{
for(i=1;i<=29;i++)
...{
days.Add(i);
}

}

else
...{
for(i=1;i<=28;i++)
...{
days.Add(i);
}

}

break;
case4:
case6:
case9:
case11:
for(i=1;i<=30;i++)
...{
days.Add(i);
}

break;
}

DropDownList3.DataSource
=days;
DropDownList3.DataBind();

}

protected void DropDownList1_SelectedIndexChanged( object sender,EventArgse)
... {
intyear,month;
Int32.TryParse(DropDownList1.SelectedValue.ToString(),
outyear);
Int32.TryParse(DropDownList2.SelectedValue.ToString(),
outmonth);
binddropdownlist3(year,month);
}

protected void DropDownList2_SelectedIndexChanged( object sender,EventArgse)
... {
intyear,month;
Int32.TryParse(DropDownList1.SelectedValue.ToString(),
outyear);
Int32.TryParse(DropDownList2.SelectedValue.ToString(),
outmonth);
binddropdownlist3(year,month);
}

但是这种做法会刷新页面,不是很好!

你可能感兴趣的:(list)