Export (0) Print
Expand All

CalendarDay.Date Property

Gets the date represented by an instance of this class. This property is read-only.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

'Declaration
Public ReadOnly Property Date As DateTime
'Usage
Dim instance As CalendarDay
Dim value As DateTime

value = instance.Date

/** @property */
public DateTime get_Date ()

public function get Date () : DateTime

Property Value

A System.DateTime object that contains the date represented by an instance of this class. This allows you to programmatically control the appearance or behavior of the day, based on this value.

Use the Date property to programmatically determine the date represented by an instance of this class.

The following example demonstrates how to use the Date property to compare the date being rendered in the DayRender event with today's date. If the date is today's date, it is displayed in a yellow cell with red text on the Calendar control.

<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<head>

   <script language="VB" runat="server">
        Sub DayRender(source As Object, e As DayRenderEventArgs)
            
            If e.Day.Date = calendar1.TodaysDate Then
                e.Cell.BackColor = System.Drawing.Color.Yellow
                e.Cell.ForeColor = System.Drawing.Color.Red
            End If
        End Sub 'DayRender 
  </script>
 
</head>
 
<body>
 
   <form runat="server">
 
      <asp:Calendar id="calendar1" runat="server"
           WeekendDayStyle-BackColor="gray"
           OnDayRender="DayRender"/>
                   
   </form>
         
</body>
</html>
   

<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>

   <script runat="server">
   
      Sub DayRender(sender 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("<br>Holiday"))
         
         End If

      End Sub

      Sub Page_Load(sender As Object, e As EventArgs)

         ' Manually register the event-handling method for the DayRender  
         ' event of the Calendar control.
         AddHandler Calendar1.DayRender, AddressOf DayRender

      End Sub

   </script>
 
</head>
 
<body>
 
   <form runat="server">

      <h3>Calendar DayRender Example</h3>
 
      <asp:Calendar id="Calendar1" 
                    runat="server">

         <WeekendDayStyle BackColor="gray">
         </WeekendDayStyle>

      </asp:Calendar>
                   
   </form>
          
</body>
</html>
   

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft