There are three DROPDOWNLIST controls on the ASPX page.
DropDownList1 represents the year, DropDownList2 represents the month, DropdownList3 means the day; note that use the AutoPostBack property of these three DROPDOWNLIST controls to True.
Users can easily choose the Year and Moon, and the monthly date will change according to the month, monthly
The code code of its inautions is as follows:
Private void page_load (object sender, system.eventargs e) {datetime t1 = datetime.now; // current 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 // Select the current year DropDownList1.selectedValue = T1.Year.toString (); DropDownList2.datasource = Almonth; DropDownList2.Database (); // Binding month // Select the current month dropdownlist2.selectedValue = TNOW.MONTH.TOSTRING (); int year, month; year = int32.parse (DropdownList1.selected); month = int32.parse (Dropdownlist2.selectedValue); binddays (year, month); // Binding day // Select the current date DropDownList3.selectedValue = T1OW.DAY.TOSTRING ();}}
// Judgment Leapnian Private Bool Checkleap (Int Year) {IF ((Year% 4 == 0) && (Year% 100! = 0) || (Year% 400 == 0)) Return True; Else Return False;} // Bind the monthly number of days 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 ) alDay.add (i);} Break; Case 4: Case 6: Case 9: Case 11: for (i = 1; i <= 30; i ) AlDay.Add (i); break;} DropDownList3.DataSource = AlDay; DropDownList3.DataBind ();} // selection private void DropDownList1_SelectedIndexChanged (object sender, System.EventArgs e) { INT Year, Month; Year = int32.Parse (DropdownList1.SelectedValue); month = int32.parse (DropdownList2.selectedValue); binddays (year, month);} // select month
private void DropDownList2_SelectedIndexChanged (object sender, System.EventArgs e) {int year, month; year = Int32.Parse (DropDownList1.SelectedValue); month = Int32.Parse (DropDownList2.SelectedValue); BindDays (year, month);}