NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Customizing Individual Days

By default, days in the Calendar Web control are simply displayed as numbers. (If day selection is enabled, the numbers appear as links. For details, see Controlling User Date Selection.) However, you can customize the appearance and content of individual days, which allows you to:

When the Calendar control is creating the output to send to the browser, it raises an OnDayRender event you can handle. The control calls your handler for each day as it is preparing the day for display, and you can then programmatically examine which date is being rendered and customize it appropriately.

The OnDayRender event handler takes two arguments, a reference to the control raising the event (the calendar control) and an object of type DayRenderEvent. The DayRenderEvent object provides access to two additional objects:

To customize the appearance of an individual day

  1. Create a handler for the Calendar control's OnDayRender event. The event should have the following signature:
    [Visual Basic]
    Public Sub Calendar1_DayRender(s As Object, _
        e As DayRenderEvent)
  2. In the handler, set properties of the Cell object available via the DayRenderEvent argument, as in the following example:
    [Visual Basic]
    Set e.Cell.BackColor = Colors.Red

The following example shows a simple but complete handler that illustrates how to change the appearance of individual days. The handler causes every other day in the calendar to be rendered in green; alternating days are rendered in the default day color.

[Visual Basic]
public Sub Calendar1_OnDayRender (sender as Object, _
      e as DayRenderEventArgs)
   With e
      If Not .Day.IsOtherMonth And .Day.DayNumberText Mod 2 = 0 Then
         ' For even-numbered days in the current month,
         ' set the background color of the cell to green.
         .Cell.BackColor = System.Drawing.Color.FromString("Green")
      EndIf
   End With
End Sub

To specify that an individual day can be selected

To add content to an individual day

See Also

Using the Calendar Web Control