Export (0) Print
Expand All

Calendar::OnDayRender Method

Raises the DayRender event of the Calendar control and allows you to provide a custom handler for the DayRender event.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

protected:
virtual void OnDayRender(
	TableCell^ cell, 
	CalendarDay^ day
)

Parameters

cell
Type: System.Web.UI.WebControls::TableCell

A TableCell that contains information about the cell to render.

day
Type: System.Web.UI.WebControls::CalendarDay

A CalendarDay that contains information about the day to render.

Although data binding is not supported for the Calendar control, it is possible to modify the content and formatting of the individual date cells. Before the Calendar control is displayed on the Web page, it creates and assembles the components that make up the control. The DayRender event is raised when each date cell in the Calendar control is created. You can control the contents and formatting of a date cell when it is created by providing code in the event handler for the DayRender event.

The event handler receives a DayRenderEventArgs object that contains event data. The DayRenderEventArgs object contains two properties that you can use to programmatically control the format of the date cell. The Cell property represents the cell being rendered, while the Day property represents the date to render in the cell.

You can also customize the contents of a cell by dynamically adding controls to the Control::Controls collection of the Cell property.

NoteNote

Because the DayRender event is raised while the Calendar control is being rendered, you cannot add a control that can also raise an event, such as LinkButton. You can only add static controls, such as System.Web.UI::LiteralControl, Label, Image, and HyperLink.

Raising an event invokes the event handler through a delegate. For more information, see Events and Delegates.

The OnDayRender method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

Notes to Inheritors

When overriding OnDayRender in a derived class, be sure to call the base class's OnDayRender method so that registered delegates receive the event.

The following code example demonstrates how to specify and code a handler for the DayRender event to make the background color yellow for the days in the displayed month. It also demonstrates how to customize the contents of a cell by adding a System.Web.UI::LiteralControl control to the cell.

No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft