CalendarDay.IsToday 属性

定义

获取一个值,该值指示由此类的实例表示的日期是否与 TodaysDate 控件的 Calendar 属性所指定的日期相同。 此属性为只读。

public:
 property bool IsToday { bool get(); };
public bool IsToday { get; }
member this.IsToday : bool
Public ReadOnly Property IsToday As Boolean

属性值

如果由此类的实例表示的日期与由 TodaysDate 控件的 Calendar 属性指定的日期相同,则为 true;否则为 false

示例

下面的示例演示如何使用 IsToday 属性来确定 事件中 DayRender 呈现的日期是否为当前日期。 如果日期是当前日期,则显示在带有红色文本的黄色单元格中 Calendar。 请注意,Day传入事件处理程序的 DayRenderEventArgs 对象的 属性是 CalendarDayDayRender 对象。

<%@ 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>ASP.NET Example</title>
<script language="C#" runat="server">

      void DayRender(Object source, DayRenderEventArgs e) 
      {
      
         if (e.Day.IsToday)
         {
            e.Cell.BackColor=System.Drawing.Color.Yellow;
            e.Cell.ForeColor=System.Drawing.Color.Red;
         }  
      
      }

   </script>
 
</head>
 
<body>
 
   <form id="form1" runat="server">
 
      <asp:Calendar id="calendar1" runat="server"
           WeekendDayStyle-BackColor="gray"
           OnDayRender="DayRender"/>
                   
   </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>ASP.NET Example</title>
<script language="VB" runat="server">
        Sub DayRender(source As Object, e As DayRenderEventArgs)
            If e.Day.IsToday Then
                e.Cell.BackColor = System.Drawing.Color.Yellow
                e.Cell.ForeColor = System.Drawing.Color.Red
            End If
        End Sub 'DayRender  
   </script>
 
</head>
 
<body>
 
   <form id="form1" runat="server">
 
      <asp:Calendar id="calendar1" runat="server"
           WeekendDayStyle-BackColor="gray"
           OnDayRender="DayRender"/>
                   
   </form>
         
</body>
</html>

注解

IsToday使用 属性以编程方式确定此类实例表示的日期是否与控件的 Calendar 属性指定的TodaysDate日期相同。 这使您可以基于该值以编程方式控制日期的外观或行为。

注意

尽管 属性指定的 TodaysDate 日期通常是服务器上的系统日期,但可以根据需要对其进行更改。

适用于

另请参阅