DayRenderEventArgs 类
定义
public ref class DayRenderEventArgs sealed
public sealed class DayRenderEventArgs
type DayRenderEventArgs = class
Public NotInheritable Class DayRenderEventArgs
- 继承
-
DayRenderEventArgs
示例
下面的代码示例演示如何为事件指定和编写处理程序的代码, DayRender 以使背景色在显示的月份中的日期为黄色。The following code example demonstrates how to specify and code a handler for the DayRender event to make the background color yellow for the days in the displayed month. 它还演示了如何通过将 System.Web.UI.LiteralControl 控件添加到单元格来自定义单元格的内容。It also demonstrates how to customize the contents of a cell by adding a System.Web.UI.LiteralControl control to the cell.
<%@ 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 修改各个日期单元的内容和格式设置。Although data binding is not supported for the Calendar control, it is possible to modify the content and formatting of the individual date cells. 在 Calendar 控件显示在网页上之前,它将创建并汇编构成控件的组件。Before the Calendar control is displayed on the Web page, it creates and assembles the components that make up the control. DayRender当创建控件中的每个日期单元格时,将引发事件 Calendar 。The DayRender event is raised when each date cell in the Calendar control is created. 可以通过在事件的事件处理程序中提供代码来控制日期单元格的内容和格式设置 DayRender 。You can control the contents and formatting of a date cell when it is created by providing code in the event handler for the DayRender event.
事件处理程序接收 DayRenderEventArgs 包含事件数据的对象。The event handler receives a DayRenderEventArgs object that contains event data. 使用 Cell 属性访问正在呈现的单元格。Use the Cell property to access the cell being rendered. 若要访问呈现的日期的属性,请使用 Day 属性。To access the properties of the day being rendered, use the Day property. 自定义单元格的内容时,您可能希望在用户选择呈现的日期时保留回发行为。When customizing the content for a cell, you might want to preserve the postback behavior when the user selects the date being rendered. 这通常通过呈现用于将页面作为自定义内容的一部分进行发布的脚本来完成。This is typically done by rendering the script used to post the page as part of the custom content. 若要检索用于将页面回发到服务器的脚本,请使用 SelectUrl 属性。To retrieve the script used to post the page back to the server, use the SelectUrl property.
有关实例的初始属性值的列表 DayRenderEventArgs ,请参见 DayRenderEventArgs 构造函数。For a list of initial property values for an instance of DayRenderEventArgs, see the DayRenderEventArgs constructor.
有关如何处理事件的详细信息,请参阅 处理和引发事件。For more information about how to handle events, see Handling and Raising Events.
构造函数
| DayRenderEventArgs(TableCell, CalendarDay) |
使用指定的单元格和日历日初始化 DayRenderEventArgs 类的新实例。Initializes a new instance of the DayRenderEventArgs class using the specified cell and calendar day. |
| DayRenderEventArgs(TableCell, CalendarDay, String) |
使用指定的单元格、日历日和选择 URL 初始化 DayRenderEventArgs 类的新实例。Initializes a new instance of the DayRenderEventArgs class using the specified cell, calendar day, and selection URL. |
属性
| Cell |
获取表示呈现在 TableCell 控件中的单元格的 Calendar 对象。Gets the TableCell object that represents the cell being rendered in the Calendar control. |
| Day |
获取表示呈现在 CalendarDay 控件中的日期的 Calendar 对象。Gets the CalendarDay object that represents the day being rendered in the Calendar control. |
| SelectUrl |
获取在 Calendar 控件中选择呈现的日期时用于将此页回发至服务器的脚本。Gets the script used to post the page back to the server when the date being rendered is selected in a Calendar control. |
方法
| Equals(Object) |
确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
| GetHashCode() |
作为默认哈希函数。Serves as the default hash function. (继承自 Object) |
| GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
| MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
| ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |