DayRenderEventArgs 类

定义

DayRender 控件的 Calendar 事件提供数据。 此类不能被继承。

public ref class DayRenderEventArgs sealed
public sealed class DayRenderEventArgs
type DayRenderEventArgs = class
Public NotInheritable Class DayRenderEventArgs
继承
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>

注解

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

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

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

有关如何处理事件的详细信息,请参阅 处理和引发事件

构造函数

DayRenderEventArgs(TableCell, CalendarDay)

使用指定的单元格和日历日初始化 DayRenderEventArgs 类的新实例。

DayRenderEventArgs(TableCell, CalendarDay, String)

使用指定的单元格、日历日和选择 URL 初始化 DayRenderEventArgs 类的新实例。

属性

Cell

获取表示呈现在 TableCell 控件中的单元格的 Calendar 对象。

Day

获取表示呈现在 CalendarDay 控件中的日期的 Calendar 对象。

SelectUrl

获取在 Calendar 控件中选择呈现的日期时用于将此页回发至服务器的脚本。

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅