There are three DropDownList controls on the ASPX page,
DropDownList1 said the year, DropDownList2 said the month, DropDownList3 said days;
Note Set the AutoPostBack property of these three DropDownList controls to true.
Users can easily select the year and month, and the monthly date will change with the user selection of different years, months and corresponding changes
The following table CS file code is as follows:
private void Page_Load (object sender, System.EventArgs e)
{
DateTime tnow=datetime.now;//now time
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 ()//binding year
Choose to be the year before
Dropdownlist1.selectedvalue=tnow. Year.tostring ();
Dropdownlist2.datasource=almonth;
Dropdownlist2.databind ()/Bind month
Select Current Month
Dropdownlist2.selectedvalue=tnow. Month.tostring ();
int year,month;
Year=int32.parse (Dropdownlist1.selectedvalue);
Month=int32.parse (Dropdownlist2.selectedvalue);
Binddays (year,month);//Bind Day
Select Current Date
Dropdownlist3.selectedvalue=tnow. Day.tostring ();
}
}
Judging leap years
private bool Checkleap (int year)
{
if ((year%4==0) && (year%100!=0) | | (year%400==0))
return true;
else return false;
}
Bind the number of days per month
private void binddays (int year,int month)
{int i;
ArrayList alday=new ArrayList ();
Switch (month)
{
Case 1:
Case 3:
Case 5:
Case 7:
Case 8:
Case 10:
Case 12:
for (i=1;i<=31;i++)
Alday.add (i);
Break
Case 2:
if (Checkleap (year))
{for (i=1;i<=29;i++)
Alday.add (i);}
Else
{for (i=1;i<=28;i++)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.