Method for monitoring Calendar event in DataList

xiaoxiao2021-03-06  42

Sometimes you want to join in the DataList's editing template to add system.web.ui.webcontrols.calendar so you can change the date attribute through Calendar, just a little, you don't need user to fill in the fixed format. Date. However, in DataList.Web.ui.WebControls.calendar control, click Calendar, it is unable to respond to SelectDate events. It is just simple submission, it will not leave itemcreated, itembound, select, edit, update, ca Zancel et al. Waiting for DataList time. (Maybe, but not found) this is the problem that this post wants to solve. I have found it in this version. I didn't see some people discussed this problem. Of course this should be solved if using client controls. However, this person is more strouped, I don't want to use Plum Rain, I do a server-side control to parse the parameters of Calendar submit form in DataList (mainly form ["__ eventargument"] and form [__ evenettarget "] two form hidden Domain) and save the results in this control, which can be accessed later.

I put the solution to the code below, I hope everyone will take a brick, give more opinions, I have improved! :)

Monitor Calendar Control CageCalendar.dllusing System; use system.web.ui.webcontrols; using system.collections.specialize;

Namespace Cage {////

/// CAGECALENDAR Returns selected by the CANlendar control by detecting the two form hidden domains of the client CANlendar by detecting the two form hidden domains in Form_Eventargument and /// __EventTarget. date. This control is mainly used in the processing of Calendar response events in /// DataList and DataGrid, and CAGE is somewhat named. /// public class CageCalendar: System.Web.UI.Control {private DateTime dtSniffTime; public CageCalendar () {} // Store the date, so that the properties can be stored in ViewState public DateTime SniffTime {get { Return DTSniffTime;} set {dtsniftime = value;}}

/// Remove the corresponding time object /// principle by relative to the daily flight of January 1, 2000: Detection form __eventargument and __EventTarget These two form hidden domains, if legal, will be resolved Parameter pass to help class /// return date, if not legal, return new datetime () /// nameValueCollection form: Web form property set /// String StrfindControlPath: DataList control path to search /// String strCalendarName:!! need to listen Calendar control name public DateTime GetDateTime (NameValueCollection form, string strFindControlPath, string strCalendarName) {if (form [ "__ eVENTARGUMENT"] = null && form [ "__ EVENTTARGET"] = null && form [ "__ eVENTARGUMENT" ]! = "" && form ["__ evenettarget"]! = "") {Char [] csplitArray = {':'}; string [] strpath = form ["__ evenettarget"]. TOSTRING (). Split (csplitArray); . string strTempPath = form [ "__ EVENTTARGET"] Substring (. 0, form [ "__ EVENTTARGET"] LastIndexOf ( ":")); strTempPath = strTempPath.Substring (0, strTempPath.LastIndexOf ( ":")); string strTempCalendarName = FORM ["__ EventTarget"]. Substring (Form ["__ EventTarget"]. LastIndexof (":") 1); if (strTempcalendarname! = strcalendarname) // Don't want to find the Calendar Control Return New Datet IME (); if (strTemppath! = strfindcontrolpath) // does not want to find the control path return new datetime (); if (Form ["__ Eventargument"]. Substring (0, 1)! = "v") {return getDatetime (Convert.Toint32 (Form ["__ Eventargument"]);} else {// Turn page return new datetime ();}}

Return new datetime ();

/// Returns the corresponding time object /// principle by relative to the daily flight of January 1, 2000: According to the offset calculation, the daily offset of January 1, 2000 is 0. It is a positive number, and it is a negative number /////bit of the day is a cycle every 400 years, which is caused by the leap year /// leap year or by 400 is not removed or 4 unpaid but not 100 removal. GetDateTime (int ipos) {ISIGN = 1; if (IPOS <0) {isign = -1;} = (-1) * ipos;} int year4 = (365 * 4 1); // General 4 years Day int year400 = year4 * 100-3; // 400 years old days, cycle int [] Year100Array = {Year4 * 25, Year4 * 25-1, Year4 * 25-1, Year4 * 25-1}; // 400 In the year, every 100 years of days int [] Montharray = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // December, the general days Int [] YeaRray = {366, 365, 365, 365}; // 4 years in the general days INT IYARBY400 = ipos / year400; // 400 years = IYEARBY400RESIDUE = IPOS% Year400; // 400 = 0 = 0; // 100 years Multiple IYEARBY100RESIDUE = 0; // 100 Years INT IYEARBY4 = 0; // 4 years ing IYEARBY4RESIDUE = 0; // 4 Years Int Iyearin4 = 0; // 4 years this small section Year INT IYARRESIDUE = 0; // 4 years in this small period in the remaining number of days in the year INT IYEAR = 0; // year intimonth = 0; // month Int iDay = 0; // day Int iMonthResidue = 0 ; // moon offset IF (Iyearby400Residue == 0) {// 400 year iodiear = 2000 isign * 400 * Iyearby400; Return New DateTime (Iyear, 1, 1);}

INT IYAR100START = (Year100Array.Length) * (1-Isign) / 2- (1-isign) / 2; int =year100nd = (Year100aRRAY.LENGTH) * (1 ISIGN) / 2- (1-isign) / 2;

iYearBy100Residue = iYearBy400Residue; for (int i = iYear100Start; i = iYear100End; i = i iSign!) {// 100 which calculates years iYearBy100Residue = iYearBy100Residue - Year100Array [i]; if (iYearBy100Residue <0) {iYearBy100 = iSign * (i - iYear100Start); iYearBy100Residue iYearBy100Residue Year100Array [i] =; break;} else if (iYearBy100Residue == 0) {// 100 years iYearBy100 = iSign * (i - iYear100Start) 1; iYear = 2000 iSign * (400 * Iyearby400 100 * IYARBY100); Return New DateTime (IYEAR, 1, 1);}}}} (isign> 0) {IF (IYARBY100 == 0) {IYARBY4 = IYARBY100RESIDUE / YEAR4; // 4 years Iyearby4residue = Iyearby100Residue% Year4; // 4 years} else {IF ((iYearby100Residue- (Year4-1)) == 0) // is not a leap year without 400, should be reduced by 1 {IYARBY4 = 1 // 4 years = 0; // 4 years} else IF ((iYarby100Residue- (Year4-1)) <0) {iYearby4 = 0; // 4 years iodiearby4residue = Iyearby100Residue; // 4 years} else { Iyearby4 = (iYARBY100RESIDUE- (YEAR4-1)) / year4 1; // 4 years of multiple iodierby4residue = (iYarby100Residue- (Year4-1))% Year4; // 4 years}}} else {Iyearby4}} else {Iyearby4 = IYARBY100RESIDUE / Year4; // 4 years of multiple iodarby4residue = IYARBY100RESIDUE% YEAR4; // 4 years}

INT IYEARSTART = (Yeararray.Length) * (1-ISIGN) / 2- (1-isign) / 2; int iod = (YeaRRay.Length) * (1 isign) / 2- (1-isign) / 2; INT IMONTHSTART = (MONTHHHHHHARRAY.LENGTH) * (1-ISIGN) / 2- (1-isign) / 2; intimonthend = (Montharray.Length) * (1 isign) / 2- (1-isign) / 2; IyearResidue = Iyearby4Residue; if (iYearResidue == 0) {// 4 Whole year IYEAR = 2000 ISIGN * (400 * IYARBY400 100 * IYARBY100 4 * Iyearby4); return new datetime (Iyear, 1, 1);} for (INT i = IyearStart; i! = iyerend; i = i isign) {// calculating the year IYARRESIDUE = IYARRESIDUE - YeaRray [i]; if (iYearResidue <= 0) {// find the absolute offset of the year, relative In 2000! Iyearin4 = isign * (i - xiearstart) (1-isign) / 2; IyearResidue = IYARRESIDUE YEARARRAY [i]; // calculate the month IF (i == 0) Montharray [2] = Montharray [2] 1 ; // Consider the month

IMONTHRESIDUE = IYARRESIDUE; for (int J = IMONTHSTART; J! = IMONTHEND; J = J ISign) {IMONTHRESIDUE = IMONTHRESIDUE-MONTHHHHARRAY [J]; IF (IMONTHRESIDUE <= 0) {// Find month! IMONTH = J 1; IDAY = IMONTHRESIDUE MONTHHHHHHARRAY [J]; // Offset Recovery iDay = Isign * iDay (1-Isign) / 2 * Montharray [J]; // Computation Day Break;}} iDay = IDAY 1; // Date is starting with 1, not zero

IF (iDay-montharray [IMONTH-1]> 0) {// Detection is beyond the month iDay = iDay - Montharray [IMONTH-1];

IMONTH ; IF (IMONTH> 12) {// Detection is exceeded by IMONTH = 1; Iyearin4 ;}}

Break;}}

Iyear = 2000 isign * (400 * Iyearby400 100 * Iyearby100 4 * Iyearby4 Iyearin4);

Return New DateTime (Iyear, IMONTH, IDAY);

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

New Post(0)