DayRenderEventHandler 委托
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
public delegate void DayRenderEventHandler(System::Object ^ sender, DayRenderEventArgs ^ e);
public delegate void DayRenderEventHandler(object sender, DayRenderEventArgs e);
type DayRenderEventHandler = delegate of obj * DayRenderEventArgs -> unit
Public Delegate Sub DayRenderEventHandler(sender As Object, e As DayRenderEventArgs)
参数
- sender
- Object
事件源。
包含事件数据的 DayRenderEventArgs。
示例
下面的代码示例演示如何指定和编码 事件的处理程序, DayRender 使显示月份中的日期的背景色为黄色。 它还演示了如何通过向单元格添加 System.Web.UI.LiteralControl 控件来自定义单元格的内容。
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>DayRender Event Example</title>
<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 id="form1" 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" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>DayRender Event Example</title>
<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 id="form1" 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" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Calendar DayRender Example</title>
<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 id="form1" runat="server">
<h3>Calendar DayRender Example</h3>
<asp:Calendar id="Calendar1"
runat="server">
<WeekendDayStyle BackColor="gray">
</WeekendDayStyle>
</asp:Calendar>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Calendar DayRender Example</title>
<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 id="form1" runat="server">
<h3>Calendar DayRender Example</h3>
<asp:Calendar id="Calendar1"
runat="server">
<WeekendDayStyle BackColor="gray">
</WeekendDayStyle>
</asp:Calendar>
</form>
</body>
</html>
注解
尽管 控件不支持 Calendar 数据绑定,但可以修改单个日期单元格的内容和格式。 在 Calendar 控件显示在网页上之前,它会创建并组合构成控件的组件。 创建 DayRender 控件中的每个日期单元格时, Calendar 将引发 事件。 通过在事件的事件处理程序 DayRender 中提供代码,可以在创建日期单元格时控制日期单元格的内容和格式。 有关自定义日期单元格内容的详细信息,请参阅 OnDayRender。
创建 DayRenderEventHandler 委托时,需要标识将处理该事件的方法。 若要将事件与事件处理程序关联,请将该委托的一个实例添加到事件中。 除非移除了该委托,否则每当发生该事件时就会调用事件处理程序。 有关事件处理程序委托的详细信息,请参阅 处理和引发事件。
扩展方法
GetMethodInfo(Delegate) |
获取指示指定委托表示的方法的对象。 |