The
Calendar control displays a month calendar from which users can select dates. The following sample illustrates using a simple
Calendar control.
C# Calendar1.aspx
Date Selection Modes
Calendar supports four date selection modes, as described in the following table.
| Mode |
Description |
| Day |
User can select any single day. |
| DayWeek |
User can select a single day, or an entire week. |
| DayWeekMonth |
User can select a single day, an entire week, or the entire visible month. |
| None |
Date selection is disabled. |
The following sample demonstrates mode selection with a
Calendar control.
C# Calendar2.aspx
Selection Link Graphics
The
Calendar control can use either text or graphics for its selection links. The following sample shows how to use graphics to create a better-looking calendar.
C# Calendar3.aspx
Selection Link Text
The
Calendar control can also use text labels for week or month selection, as shown in the following example.
C# Calendar4.aspx
Adding Custom Content to Calendar
You can make appointment-style calendars by adding content in the
OnDayRender event. Two of the arguments for
OnDayRender are the
Day that is being rendered and its
Cell object. Custom text can be added to the cell for a particular day by adding it as a
LiteralControl to the
Cell object's Controls collection, as shown in the following example.
| C# |
VB |
|
string Hol = GetHoliday(Day.Date);
if (Hol != string.Empty) Cells.Controls.Add(new LiteralControl("<br>" + Hol));
Dim Hol As String = GetHoliday(Day.Date)
If Hol <> String.Empty Then Cells.Controls.Add(New LiteralControl("<br>" + Hol))
|
C# Calendar5.aspx