DayRenderEventHandler 委托

表示处理 Calendar 控件的 DayRender 事件的方法。

**命名空间:**System.Web.UI.WebControls
**程序集:**System.Web(在 system.web.dll 中)

语法

声明
Public Delegate Sub DayRenderEventHandler ( _
    sender As Object, _
    e As DayRenderEventArgs _
)
用法
Dim instance As New DayRenderEventHandler(AddressOf HandlerMethod)
public delegate void DayRenderEventHandler (
    Object sender,
    DayRenderEventArgs e
)
public delegate void DayRenderEventHandler (
    Object^ sender, 
    DayRenderEventArgs^ e
)
/** @delegate */
public delegate void DayRenderEventHandler (
    Object sender, 
    DayRenderEventArgs e
)
JScript 支持使用委托,但不支持进行新的声明。

参数

  • sender
    事件源。

备注

尽管对于 Calendar 控件不支持数据绑定,但您可以修改各个日期单元格的内容和格式设置。在网页上显示 Calendar 控件之前,它创建并汇编组成该控件的组件。当创建 Calendar 控件中的每个日期单元格时,均会引发 DayRender 事件。通过在 DayRender 事件的事件处理程序中提供代码,可以在创建日期单元格时控制其内容和格式设置。有关自定义日期单元格内容的更多信息,请参见 OnDayRender

当创建 DayRenderEventHandler 委托时,将标识处理事件的方法。若要使该事件与事件处理程序相关联,请将该委托的一个实例添加到事件中。除非移除了该委托,否则每当发生该事件时就调用事件处理程序。有关事件处理程序委托的更多信息,请参见 事件和委托

示例

下面的代码示例演示如何为 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

请参见

参考

System.Web.UI.WebControls 命名空间
DayRenderEventArgs 类
Calendar 类
Calendar.DayRender 事件
TableCell
CalendarDay 类