DayRenderEventArgs 类

Calendar 控件的 DayRender 事件提供数据。无法继承此类。

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

语法

声明
Public NotInheritable Class DayRenderEventArgs
用法
Dim instance As DayRenderEventArgs
public sealed class DayRenderEventArgs
public ref class DayRenderEventArgs sealed
public final class DayRenderEventArgs
public final class DayRenderEventArgs

备注

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

事件处理程序接收包含事件数据的 DayRenderEventArgs 对象。使用 Cell 属性来访问呈现的单元格。若要访问呈现的日期的属性,请使用 Day 属性。自定义单元格的内容时,您可能想在用户选择呈现的日期时保留回发行为。这通常通过呈现用于将此页作为自定义内容的一部分来发送的脚本来完成。若要检索用于将此页回发到服务器的脚本,请使用 SelectUrl 属性。

有关 DayRenderEventArgs 的实例的初始属性值列表,请参见 DayRenderEventArgs 构造函数。

有关处理事件的更多信息,请参见 使用事件

主题 位置
如何:在 Calendar Web 服务器控件中自定义个别日 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:在 Calendar Web 服务器控件中自定义个别日 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:在 Calendar Web 服务器控件中自定义个别日 生成 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>
   

.NET Framework 安全性

继承层次结构

System.Object
  System.Web.UI.WebControls.DayRenderEventArgs

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

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

请参见

参考

DayRenderEventArgs 成员
System.Web.UI.WebControls 命名空间
Calendar 类
DayRenderEventHandler
Calendar.DayRender 事件
TableCell
CalendarDay 类
Cell
Day
SelectUrl

其他资源

使用事件