Asp. NET Calarder calendar controls support holiday notifications

Source: Internet
Author: User
Tags datetime

The following describes the common attributes of the Calarder control:

SelectionMode: Specifies whether to select the day, week, and whole month. It is a CalendarSelectionMode enumeration;

SelectedDate: gets or sets the currently selected time, which is a DateTime structure;

VisibleDate: the date used to obtain or set the date displayed in the calendar. It is a DateTime structure;

PrevMonthText: indicates the symbol used to switch the previous month. It can be expressed as 'previous month' and is of the string type;

NextMonthText: indicates the symbol used to switch to the next month. It can be indicated by 'next month'. It is of the string type;

SelectMonthText: displays the symbols of the entire month. You can use 'select the entire month' to indicate the string type;

SelectWeekText: indicates the symbol used to display the entire week. It can be 'select', which is of the string type;

ShowGridLines: whether to display gridlines. It is of the Boolean type;

Common events:

SelectionChanged: triggered when a date is selected;

DayRender: triggered when the calendar control is loaded, which is equivalent to an OnRender event;

VisibleMonthChanged: all operations on the month are triggered;

Next, let's go to the question: how to implement the custom calendar control:

1. In the Page_Init method, instantiate a String-type two-dimensional array with the length of months and days, and then write the holiday of the corresponding date for later display, such:

The code is as follows: Copy code

Private string [] [] arr;

Protected void Page_Init (object sender, EventArgs e)
        {
Arr = new string [13] []; // monthly, respectively
For (int I = 0; I <13; I ++)
             {
Arr [I] = new string [32]; // assign values to year and month
             }
Arr [1] [1] = "New Year's Day ";
Arr [2] [14] = "Valentine's Day ";
Arr [3] [8] = "Women's Day ";
Arr [3] [20] = "sister's birthday ";
Arr [3] [12] = "Arbor Day ";
Arr [4] [16] = "mom's birthday ";
Arr [4] [29] = "My Birthday ";
Arr [5] [1] = "Labor Day ";
Arr [6] [1] = "Children's Day ";
Arr [7] [1] = "party building Festival ";
Arr [8] [1] = "Jianjun festival ";
Arr [8] [10] = "dad's birthday ";
Arr [9] [10] = "Teacher's Day ";
Arr [10] [1] = "national day ";
Arr [12] [24] = "Christmas Eve ";
Arr [12] [25] = "Christmas ";
            
        }

2. Perform operations on DayRender events;

The code is as follows: Copy code
Protected void Calendar3_DayRender (object sender, DayRenderEventArgs e)
        {
CalendarDay day = e. Day; // you can specify the current date.
TableCell cells = e. Cell; // sets the table
If (day. IsOtherMonth) // if the content is in another section, it is a date limit to clear the content Calendar in this section;
            {
Cells. Controls. Clear ();
            }
Else
            {
Try
                {
String txt = arr [day. Date. Month] [day. Date. Day]; // obtain the complete Month and day matching the array.
If (! String. IsNullOrEmpty (txt) // You can check whether a holiday exists.
                    {
Cells. controls. add (new LiteralControl (string. format ("<br> <font color = red> {0} </font>", txt); // add the red string after the displayed date
                    }
                }
Catch (Exception)
                {
Response. Write ("<font color = 'red'>                 }
            }
        }

The display can be completed here, but we want to display the calendar of the link as the blog Garden does. For example, if we send a blog today, we need to highlight the date and have a hyperlink, how can this problem be achieved? I will go back to the second blog.

Related Article

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.