The Calendar class is under System.Web.UI namespace.
By placing a simple tag in a Web form, you can render an HTML-based calendar that can accept user input.
The Calendar Web control is instantiated like this:
<asp:Calendar id="MyCalendar" runat="server"></asp:Calendar>
Properties of the Calendar Class
Item | Description |
CellPadding | Specifies the padding distance inside cells in the Calendar control |
CellSpacing | Specifies the amount of spacing between cells in the Calendar control |
DayHeaderStyle | Specifies style and format information for the day headers |
DayNameFormat | Specifies the format of the day names |
DayStyle | Specifies style and format information for the days in the month |
FirstDayOfWeek | Specifies the first calendar day of the week |
NextMonthText | Specifies the text to display in the hyperlink to show next month |
NextPrevFormat | Specifies the format of the next and previous month navigation elements |
NextPrevStyle | Specifies style and format information tp apply to the next and previous month navigation elements |
OtherMonthDayStyle | Specifies style and format information for days on the calendar that are not in the current month |
PrevMonthText | Spcifies the text of the hyperlink which shows the previous month |
SelectedDate | Specifies the currently selected date |
SelectedDayStyle | Specifies the style and format of the day the user has selected |
SelectionMode | Specifies the selection choices a user has available |
SelectMonthText | Specifies the text of the hyperlink that enables a user to select an entire month |
SelectorStyle | Contains the style and format information for the week and month selection elements |
SelectWeekText | Specifies the text to be displayed next to the weeks that will enable a user to select a week at a time |
ShowDayHeader | Specifies whether the header row on the Calendar control should be displayed |
ShowGridLines | Specifies whether the Calendar grid lines should be rendered |
ShowNextPrevMonth | Specifies whether the next and previous month links should appear |
ShowTitle | Specifies whether the Calendar title is rendered |
TitleFormat | Specifies the format of the title |
TitleStyle | Contains style and format information for the Calendar title |
TodayDayStyle | Contains style and format information for the current day |
TodaysDate | Specifies the current date |
VisibleDate | Specifies the date used to determine which month to display on the rendered calendar |
WeekendDayStyle | Contains style and format information for the Weekend day |
Syntax
Int32 CellPadding
Description
The Calendar.CellPadding property changes the padding distance between cells in the Calendar control.
Example
MyCalendar.CellPadding = 4;
Syntax
Int32 CellSpacing
Description
The Calendar.CellSpacing property specifies the amount of spacing between cells in the Calendar control.
Example
MyCalendar.CellSpacing = 4;
Syntax
TableItemStyle DayHeaderStyle
Description
The Calendar.DayHeaderStyle property specifies style and format information for the day headers at the top of the Calendar control.
Example
MyCalendar.DayHeaderStyle.CssClass = "main";
Syntax
DayNameFormat DayNameFormat
Description
The Calendar.DayNameFormat property specifies the format of the day names as rendered by the Calendar control. Valid values are FirstLetter, FirstTwoLetters, Full, and Short. Short is the default value.
Example
MyCalendar.DayNameFormat = DayNameFormat.Full;
Syntax
TableItemStyle DayStyle
Description
The Calendar.DayStyle property specifies style and format information for the days in the month.
Example
MyCalendar.DayStyle.CssClass = "main";
Syntax
FirstDayOfWeek FirstDayOfWeek
Description
The Calendar.FirstDayOfWeek property specifies the first calendar day of the week. Sunday is the default first day of the week.
Example
MyCalendar.FirstDayOfWeek = FirstDayOfWeek.Wednesday;
Syntax
String NextMonthText
Description
The Calendar.NextMonthText property specifies the text to display in the header of the Calendar control that directs the user to click to the next month. By default, this property is blank.
Example
MyCalendar.NextMonthText = "Next Month>";
Syntax
NextPrevFormat NextPrevFormat
Description
The Calendar.NextPrevFormat property specifies the format of the next and previous month navigation elements. Valid values are CustomText, FullMonth, and ShortMonth. FullMonth displays the full month name and ShortMonth displays an abbreviation.
Example
MyCalendar.NextPrevFormat = FullMonth;
Syntax
TableItemStyle NextPrevStyle
Description
The Calendar.NextPrevStyle property specifies style and format information to apply to the next and previous month navigation elements.
Example
MyCalendar.NextPrevStyle.CssClass = "header";
Syntax
TableItemStyle OtherMonthDayStyle
Description
The Calendar.OtherMonthDayStyle property specifies style and format information for days on the calendar that are not in the current month.
Example
MyCalendar.OtherMonthDayStyle.CssClass = "OtherDay";
Syntax
String PrevMonthText
Description
The Calendar.PrevMonthText property specifies the text to display in the header of the Calendar control that directs the user to click to the previous month. By default, this property is blank.
Example
MyCalendar.NextMonthText = "<Previous Month";
Syntax
DateTime SelectedDate
Description
The Calendar.SelectedDate property contains the currently selected date.
Example
DateTime MyDate = MyCalendar.SelectedDate;
Syntax
TableItemStyle SelectedDateStyle
Description
The Calendar.SelectedDayStyle property specifies the style and format of the day the user has selected.
Example
MyCalendar.SelectedDayStyle.CssClass = "SelectedDay";
Syntax
CalendarSelectionMode SelectionMode
Description
The Calendar.SelectionMode property specifies the selection choices a user has available. The user can select the day, week, or month, based on the SelectionMode property. Valid values are Day, DayWeek, DayWeekMonth, and None.
Example
MyCalendar.SelectionMode = CalendarSelectionMode.Day;
Syntax
String SelectMonthText
Description
The Calendar.SelectMonthText property enables you to specify text that will appear in the upper-left corner of the rendered calendar. When a user clicks on this text, the entire month will be selected. In order for this property to function, the Calendar.SelectionMode must be set to CalendarSelectionMode.DayWeekMonth.
Example
MyCalendar.SelectionMode = CalendarSelectionMode.DayWeekMonth; MyCalendar.SelectMonthText = "select month";
Syntax
TableItemStyle SelectorStyle
Description
The Calendar.SelectorStyle property contains the style and format information for the week and month selection elements.
Example
string cssClass = MyCalendar.SelectorStyle.CssClass;
Syntax
String SelectWeekText
Description
The Calendar.SelectWeekText property specifies the text to be displayed next to the weeks that will enable a user to select those weeks.
Example
MyCalendar.SelectWeekText = ">>";
Syntax
Boolean ShowDayHeader
Description
The Calendar.ShowDayHeader property specifies whether the header row on the Calendar control should be displayed. The default is True.
Example
MyCalendar.ShowDayHeader = false;
Syntax
Boolean ShowGridLines
Description
The Calendar.ShowGridLines property specifies whether the calendar grid lines should be rendered. The default is True.
Example
MyCalendar.ShowGridLines = false;
Syntax
Boolean ShowNextPrevMonth
Description
The Calendar.ShowNextPrevMonth property specifies whether the next and previous month links should appear. The default is True.
Example
MyCalendar.ShowNextPrevMonth = false;
Syntax
Boolean ShowTitle
Description
The Calendar.ShowTitle property specifies whether the calendar title is rendered. The default is True.
Example
MyCalendar.ShowTitle = false;
Syntax
TitleFormat TitleFormat
Description
The Calendar.TitleFormat property specifies the format of the title. Valid values are Month and MonthYear. The default is MonthYear.
Example
MyCalendar.TitleFormat = TitleFormat.Month;
Syntax
TableItemStyle TitleStyle
Description
The Calendar.TitleStyle property contains the style and format information for the calendar's title.
Example
string MyClass = MyCalendar.TitleStyle.CssClass;
Syntax
TableItemStyle TodayDayStyle
Description
The Calendar.TodayDayStyle property contains the style and format information for the current day in the calendar.
Example
string MyClass = MyCalendar.TodayDayStyle.CssClass;
Syntax
DateTime TodaysDate
Description
The Calendar.TodaysDate property specifies the current date.
Example
DateTime MyDate = MyCalendar.TodaysDate;
Syntax
DateTime VisibleDate
Description
The Calendar.VisibleDate property specifies the date used to determine which month to display in the rendered calendar.
Example
MyCalendar.VisibleDate = new DateTime(2006, 12, 1);
Syntax
TableItemStyle WeekendDayStyle
Description
The Calendar.WeekendDayStyle property contains the style and format information of weekend days in the rendered calendar.
Example
string MyClass = MyCalendar.WeekendDayStyle.CssClass;