In ASP.NET, use three DROPDOWNLIST controls to make the annual day month

xiaoxiao2021-03-05  20

DropDownList1 means that DropDownList2 means the month, DropDownList3 means the day;

Note Use the AutoPostBack properties of these three DropDownList controls to True. Users can easily choose the Year and Month Day, and the monthly date will choose a different year, the monthly CS file code 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.DatabaseD (); // Binding year

// Select the current year dropdownloadwnList1.selectedValue = T1OW.YAR.TOSTRING ();

DROPDOWNLIST2.DATASOSOURCE = Almonth; DropDownList2.Database (); // Binding month

// Select the current month dropdownlist2.selectedValue = t1ow.month.toString ();

INT Year, Month; Year = int32.parse (DropdownList1.SelectedValue); Month = int32.parse (DropdownList2.SelectedValue); binddays (year, month); // Binding day

// Select the current date DropDownList3.selectedValue = t1w.day.totTRING ();}} // 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 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 ();

}

Choice // 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) }

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

New Post(0)