Use three DROPDOWNLIST controls to choose the year and month [turn]

xiaoxiao2021-03-06  137

There are three DROPDOWNLIST controls on the ASPX page. DROPDOWNLIST1 represents the year, DropDownList2 means the month, DropDownList3 means the day; note that the autopostback property of the three DROPDOWNLIST controls is used to True.

The user can easily choose the Year and Moon, and the monthly date will change as the user chooses different years, the corresponding change has the following lattice CS file code as follows: Private Void Page_load (Object Sender, System.EventArgs E) {DateTime TNOW = datetime.now; // Today 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 = tnow.Year.ToString (); DropDownList2.DataSource = AlMonth; DropDownList2.DataBind (); // // bind month to select the current month DropDownList2.SelectedValue = tnow.Month.ToString (); int year, month; year = Int32.Parse (DropDownList1.SelectedValue); month = Int32.Parse (DropDownList2.SelectedValue); BindDays (year, month); // // bind days select the current date DropDownList3.SelectedValue = tnow.Day.ToString () ;}} // Judgment leap year 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 of the month PRI Vate void bindday {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;

转载请注明原文地址:https://www.9cbs.com/read-127752.html

New Post(0)