Version

Creating Custom Days in WebMonthCalendar

Before You Begin

WebMonthCalendar™ allows you to customize the appearance or define your own text for specific days in the calendar. Your own custom CSS classes can be used to style the text of any day in the calendar. This can be achieved by setting the control’s CustomDays property.

What You Will Accomplish

You will learn how to create custom days in WebMonthCalendar.

Follow these Steps

  1. From the Microsoft® Visual Studio® Toolbox, drag and drop a ScriptManager component and a WebMonthCalendar control onto the form.

  2. Include the following code in your ASPX source to define the CSS class for your custom day; once this CSS class is associated to the WebMonthCalendar control, the text of the custom day will change to the color red.

In HTML:

<style type="text/css">
     .myCustomDay
     {
        color : Red;
     }
    </style>
  1. In the property window, locate the CustomDays property and click the ellipsis(…) button to launch the CalendarCustomDay Collection Editor.

  2. Click the Add button to add a custom day. Your CalendarCustomDay Collection Editor looks similar to the following image:

WebMonthCalendar Using Custom Days in WebMonthCalendar 01.png
  1. Set the following CalendarCustomDay properties in the right pane of the CalendarCustomDay Collection Editor to display June 26th, 2009 with the letter 'H' in red color :

Property Value

CssClass

myCustomDay

Day

26

Month

6

Text

H

Year

2009

  1. Save and run your application. Your WebMonthCalendar now looks similar to the following image:

Creating Custom Days through the code-behind

//Create an instance of CalendarCustomDay
CalendarCustomDay myCustomDay = new CalendarCustomDay();
//Set your own Css class to the CssClass property of the custom day
myCustomDay.CssClass = "myCustomDay";
//Set the Text property to the text you want to display
myCustomDay.Text = "H";
//Set the day of the month you want to customize
myCustomDay.Day = 26;
//Set the month
myCustomDay.Month = 6;
//Set the year
myCustomDay.Year = 2009;
//Add the custom day you created to the CustomDays collection of WebMonthCalendar
WebMonthCalendar1.CustomDays.Add(myCustomDay);