CalendarDay.IsToday Propiedad

Definición

Obtiene un valor que indica si la fecha representada por una instancia de esta clase coincide con la fecha especificada por la propiedad TodaysDate del control Calendar. Esta propiedad es de sólo lectura.

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

Valor de propiedad

Es true si la fecha representada por una instancia de esta clase coincide con la fecha especificada por la propiedad TodaysDate del control Calendar; en caso contrario, es false.

Ejemplos

En el ejemplo siguiente se muestra cómo usar la IsToday propiedad para determinar si la fecha que se representa en el DayRender evento es la fecha actual. Si la fecha es la fecha actual, se muestra en una celda amarilla con texto rojo en .Calendar Tenga en cuenta que la Day propiedad del DayRenderEventArgs objeto pasado al DayRender controlador de eventos es el CalendarDay objeto .

<%@ 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>

Comentarios

Utilice la IsToday propiedad para determinar mediante programación si la fecha representada por una instancia de esta clase es la misma fecha especificada por la TodaysDate propiedad del Calendar control. Esto permite controlar mediante programación la apariencia o el comportamiento del día sobre la base de este valor.

Nota

Aunque la fecha especificada por la TodaysDate propiedad suele ser la fecha del sistema en el servidor, es posible cambiarla, si es necesario.

Se aplica a

Consulte también