Use calendar-display a specific holiday Style

Source: Internet
Author: User
In ASP. net2.0, calendar 176-9-4 17:01:07 with holiday notification is read: [Font size:Large Medium Small]

1. Create the webpage calendarree. aspx,CodeAs follows:

<% @ Page Language = "C #" autoeventwireup = "true" codefile = "calendarree. aspx. cs" inherits = "calendarree" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: Calendar id = "calendar1" runat = "server" ondayrender = "calendar#dayrender" Height = "206px" width = "369px"> </ASP: Calendar>

</Div>
</Form>
</Body>
</Html>

2. The Code of calendarree. aspx. CS is as follows:

Using system;
Using system. Data;
Using system. configuration;
Using system. collections;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;

Public partial class calendarree: system. Web. UI. Page
{
String [] [] holidays = new string [13] [];
Protected void page_load (Object sender, eventargs E)
{
For (INT n = 0; n <13; n ++)
Holidays [N] = new string [32];

Holidays [1] [1] = "New Year's Day ";
Holidays [2] [14] = "Valentine's Day ";
Holidays [3] [8] = "Women's Day ";
Holidays [3] [12] = "Arbor Day ";
Holidays [4] [1] = "";
Holidays [5] [1] = "Labor Day ";
Holidays [5] [4] = "Youth Day ";
Holidays [5] [12] = "Nurse's Day ";
Holidays [5] [14] = "Mother's Day ";
Holidays [5] [14] = "helping Day ";
Holidays [6] [1] = "International Children's Day ";
Holidays [6] [5] = "Environmental Protection Day ";
Holidays [6] [18] = "Father's Day ";
Holidays [6] [26] = "International Day ";
Holidays [7] [1] = "the birth of the Communist Party of China ";
Holidays [8] [1] = "Jianjun Festival ";
Holidays [9] [10] = "Teacher's Day ";
Holidays [10] [1] = "National Day ";
Holidays [11] [23] = "Thanksgiving Day ";
Holidays [12] [1] = "AIDS Day ";
Holidays [12] [12] = "Xi'an Incident ";
Holidays [12] [25] = "Christmas ";
}
Protected void calendar1_dayrender (Object sender, dayrendereventargs E)
{
Calendarday d = (dayrendereventargs) e). Day;
Tablecell c = (dayrendereventargs) e). cell;

If (E. Day. isothermonth)
{
E. Cell. Controls. Clear ();
}
Else
{
Try
{
String Hol = holidays [E. Day. Date. month] [E. Day. Date. Day];

If (HOL! = String. Empty)
E. Cell. Controls. Add (New literalcontrol ("<br> <font color = blue size = 2>" + Hol + "</font> "));
}
Catch (exception exc)
{
Response. Write (EXC. tostring ());
}
}
}
}

3. The running effect is as follows:

----------------------------------------------------------------------
Example 2,

Basic use of the calendar control (date format conversion and festival customization)

Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;

Public partial class _ default: system. Web. UI. Page
{
Private string [,] holiday = new string [365]; // defines an array to display days a year
Protected void page_load (Object sender, eventargs E)
{
Holiday [8, 2] = "I rely on it, I have succeeded! "; // Set August 2 as a special anniversary
}
// Date selection format
Protected void dropdownlistincluselectedindexchanged (Object sender, eventargs E)
{
String A = This. dropdownlist1.selectedvalue; // The value of the selected item in the list
Switch ()
{
Case "day ":
This. calendar1.selectionmode = calendarselectionmode. Day; // select a single date on the calendar control.
Break;
Case "month ":
This. calendar1.selectionmode = calendarselectionmode. dayweekmonth; // select a single date, week, or month on the calendar control.
Break;
Case "Week ":
This. calendar1.selectionmode = calendarselectionmode. dayweek; // select a single date or whole week on the calendar Control
Break;
Case "NONE ":
This. calendar1.selectionmode = calendarselectionmode. None; // No date can be selected on the calendar control.
Break;
}
}
Protected void calendar1_dayrender (Object sender, dayrendereventargs E)
{
Calendarday D; // D indicates the date in the control.
Tablecell C; // C is the cell in the control.
D = E. Day; // obtain the calendar day object of the date in the calendar control.
C = E. cell;
If (D. isothermonth)
C. Controls. Clear (); // remove all controls from the system. Web. UI. controlcollection object of the current server
Else
Try
{
String Hol;
Hol = holiday [D. Date. Month, D. Date. Day]; // get this instance to indicate the month and date of the date
If (HOL! = "")
C. controls. add (New literalcontrol ("<br> <font color = Red>" + Hol + "</font>"); // set the specified system. web. UI. the control object is added to the set and the system is initialized with the specified text. web. UI. new literalcontrol class instance
}
Catch (exception exc) // capture error information
{
Response. Write (EXC. Message );
}

}

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.