Calendar.DayRender 事件
当为 Calendar 控件在控件层次结构中创建每一天时发生。
**命名空间:**System.Web.UI.WebControls
**程序集:**System.Web(在 system.web.dll 中)
语法
声明
Public Event DayRender As DayRenderEventHandler
用法
Dim instance As Calendar
Dim handler As DayRenderEventHandler
AddHandler instance.DayRender, handler
public event DayRenderEventHandler DayRender
public:
event DayRenderEventHandler^ DayRender {
void add (DayRenderEventHandler^ value);
void remove (DayRenderEventHandler^ value);
}
/** @event */
public void add_DayRender (DayRenderEventHandler value)
/** @event */
public void remove_DayRender (DayRenderEventHandler value)
JScript 支持使用事件,但不支持进行新的声明。
备注
当为 Calendar 控件在控件层次结构中创建每一天时引发该事件。
尽管对于 Calendar 控件不支持数据绑定,但您可以修改各个日期单元格的内容和格式设置。在网页上显示 Calendar 控件之前,它创建并汇编组成该控件的组件。当创建 Calendar 控件中的每个日期单元格时,均会引发 DayRender 事件。通过在 DayRender 事件的事件处理程序中提供代码,可以在创建日期单元格时控制其内容和格式设置。有关自定义日期单元格内容的更多信息,请参见 OnDayRender。
提示
因为 DayRender 事件是在正呈现 Calendar 控件时引发的,所以无法添加也可以引发事件的控件,如 LinkButton。只能添加静态控件,如 System.Web.UI.LiteralControl、Label、Image 和 HyperLink。
有关处理事件的更多信息,请参见 事件和委托。
主题 | 位置 |
---|---|
如何:在 Calendar Web 服务器控件中自定义个别日 | 在 Visual Studio 中生成 ASP .NET Web 应用程序 |
如何:在 Calendar 控件中显示数据库中的选定日期 | 在 Visual Studio 中生成 ASP .NET Web 应用程序 |
如何:在 Calendar Web 服务器控件中自定义个别日 | 在 Visual Studio 中生成 ASP .NET Web 应用程序 |
如何:在 Calendar 控件中显示数据库中的选定日期 | 在 Visual Studio 中生成 ASP .NET Web 应用程序 |
如何:在 Calendar Web 服务器控件中自定义个别日 | 生成 ASP .NET Web 应用程序 |
如何:在 Calendar 控件中显示数据库中的选定日期 | 生成 ASP .NET Web 应用程序 |
示例
下面的代码示例演示如何为 DayRender 事件指定和编写处理程序,使所显示月份中日期的背景色为黄色。它还演示如何通过将 System.Web.UI.LiteralControl 控件添加到单元格来自定义单元格的内容。
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>
<script language="VB" runat="server">
Sub DayRender(source As Object, e As DayRenderEventArgs)
' Change the background color of the days in the month
' to yellow.
If Not e.Day.IsOtherMonth And Not e.Day.IsWeekend Then
e.Cell.BackColor = System.Drawing.Color.Yellow
End If
' Add custom text to cell in the Calendar control.
If e.Day.Date.Day = 18 Then
e.Cell.Controls.Add(New LiteralControl(ChrW(60) & "br" & ChrW(62) & "Holiday"))
End If
End Sub 'DayRender
</script>
</head>
<body>
<form runat="server">
<h3>DayRender Event Example</h3>
<asp:Calendar id="calendar1"
OnDayRender="DayRender"
runat="server">
<WeekendDayStyle BackColor="gray">
</WeekendDayStyle>
</asp:Calendar>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
<script language="C#" runat="server">
void DayRender(Object source, DayRenderEventArgs e)
{
// Change the background color of the days in the month
// to yellow.
if (!e.Day.IsOtherMonth && !e.Day.IsWeekend)
e.Cell.BackColor=System.Drawing.Color.Yellow;
// Add custom text to cell in the Calendar control.
if (e.Day.Date.Day == 18)
e.Cell.Controls.Add(new LiteralControl("<br>Holiday"));
}
</script>
</head>
<body>
<form runat="server">
<h3>DayRender Event Example</h3>
<asp:Calendar id="calendar1"
OnDayRender="DayRender"
runat="server">
<WeekendDayStyle BackColor="gray">
</WeekendDayStyle>
</asp:Calendar>
</form>
</body>
</html>
<%@ Page Language="JScript" AutoEventWireup="True" %>
<html>
<head>
<script language="JScript" runat="server">
function DayRender(source : Object, e : DayRenderEventArgs)
{
// Change the background color of the days in the month
// to yellow.
if (!e.Day.IsOtherMonth && !e.Day.IsWeekend)
e.Cell.BackColor=System.Drawing.Color.Yellow;
// Add custom text to cell in the Calendar control.
if (e.Day.Date.Day == 18)
e.Cell.Controls.Add(new LiteralControl("<br>Holiday"));
}
</script>
</head>
<body>
<form runat="server">
<h3>DayRender Event Example</h3>
<asp:Calendar id="calendar1"
OnDayRender="DayRender"
runat="server">
<WeekendDayStyle BackColor="gray">
</WeekendDayStyle>
</asp:Calendar>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>
<script runat="server">
Sub DayRender(sender as Object, e As DayRenderEventArgs)
' Change the background color of the days in the month
' to yellow.
If (Not e.Day.IsOtherMonth) And (Not e.Day.IsWeekend) Then
e.Cell.BackColor=System.Drawing.Color.Yellow
End If
' Add custom text to cell in the Calendar control.
If e.Day.Date.Day = 18 Then
e.Cell.Controls.Add(New LiteralControl("<br>Holiday"))
End If
End Sub
Sub Page_Load(sender As Object, e As EventArgs)
' Manually register the event-handling method for the DayRender
' event of the Calendar control.
AddHandler Calendar1.DayRender, AddressOf DayRender
End Sub
</script>
</head>
<body>
<form runat="server">
<h3>Calendar DayRender Example</h3>
<asp:Calendar id="Calendar1"
runat="server">
<WeekendDayStyle BackColor="gray">
</WeekendDayStyle>
</asp:Calendar>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
<script runat="server">
void DayRender(Object sender, DayRenderEventArgs e)
{
// Change the background color of the days in the month
// to yellow.
if (!e.Day.IsOtherMonth && !e.Day.IsWeekend)
{
e.Cell.BackColor=System.Drawing.Color.Yellow;
}
// Add custom text to cell in the Calendar control.
if (e.Day.Date.Day == 18)
{
e.Cell.Controls.Add(new LiteralControl("<br>Holiday"));
}
}
void Page_Load(Object sender, EventArgs e)
{
// Manually register the event-handling method for the DayRender
// event of the Calendar control.
Calendar1.DayRender += new DayRenderEventHandler(this.DayRender);
}
</script>
</head>
<body>
<form runat="server">
<h3>Calendar DayRender Example</h3>
<asp:Calendar id="Calendar1"
runat="server">
<WeekendDayStyle BackColor="gray">
</WeekendDayStyle>
</asp:Calendar>
</form>
</body>
</html>
平台
Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
Calendar 类
Calendar 成员
System.Web.UI.WebControls 命名空间
OnDayRender