CalendarDay 類別

定義

表示 Calendar 控制項中的日期。Represents a date in the Calendar control.

public ref class CalendarDay
public class CalendarDay
type CalendarDay = class
Public Class CalendarDay
繼承
CalendarDay

範例

下列範例示範如何使用物件的屬性, CalendarDay 來判斷在事件中轉譯的日期是否 DayRender 在顯示的月份中,而且不會落在星期六或星期日。The following example demonstrates how to use the properties of a CalendarDay object to determine whether the date being rendered in the DayRender event is in the displayed month and do not fall on Saturday or Sunday. 這些日期會以黃色顯示。These dates are displayed in yellow. 請注意, Day DayRenderEventArgs 傳遞至事件處理常式之物件的屬性 DayRenderCalendarDay 物件。Note that the Day property of the DayRenderEventArgs object passed into the DayRender event handler is the CalendarDay object.

<%@ 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.IsOtherMonth && !e.Day.IsWeekend)
            e.Cell.BackColor=System.Drawing.Color.Yellow;
      
      }

   </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 Not e.Day.IsOtherMonth And Not e.Day.IsWeekend Then
                e.Cell.BackColor = System.Drawing.Color.Yellow
            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>
   
<%@ 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 runat="server">
    <title>Calendar DayRender Example</title>
<script runat="server">
   
      void DayRender(Object sender, 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"));
         }

      }

      void Page_Load(Object sender, EventArgs e)
      {

         // Manually register the event-handling method for the DayRender  
         // event of the Calendar control.
         Calendar1.DayRender += new DayRenderEventHandler(this.DayRender);

      }

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

      <h3>Calendar DayRender Example</h3>
 
      <asp:Calendar id="Calendar1" 
                    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 runat="server">
    <title>Calendar DayRender Example</title>
<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 id="form1" runat="server">

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

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

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

備註

CalendarDay物件代表控制項中的日期 CalendarA CalendarDay object represents a date in the Calendar control. 您可以在事件處理常式中使用這個類別 DayRender ,以程式設計方式存取在控制項上呈現之日期的屬性 CalendarYou can use this class in the DayRender event handler to programmatically access the properties of a date as it is rendered on the Calendar control. 這可讓您判斷日 (的屬性,例如日期是否可選取、選取、今天的日期或週末) ,並以程式設計方式控制當天的外觀或行為。This allows you to determine the properties of the day (such as whether the date is selectable, selected, today's date, or a weekend date) and programmatically control the appearance or behavior of the day.

如需實例的初始屬性值清單 CalendarDay ,請參閱 CalendarDay 函數。For a list of initial property values for an instance of CalendarDay, see the CalendarDay constructor.

建構函式

CalendarDay(DateTime, Boolean, Boolean, Boolean, Boolean, String)

初始化 CalendarDay 類別的新執行個體。Initializes a new instance of the CalendarDay class.

屬性

Date

取得這個類別的執行個體所代表的日期。Gets the date represented by an instance of this class. 這個屬性是唯讀的。This property is read-only.

DayNumberText

取得 CalendarDay 類別的執行個體所代表的日期日數的對等字串。Gets the string equivalent of the day number for the date represented by an instance of the CalendarDay class. 這個屬性是唯讀的。This property is read-only.

IsOtherMonth

取得值,指出這個類別的執行個體所代表的日期是否在不是 Calendar 控制項上所顯示的月份中。Gets a value that indicates whether the date represented by an instance of this class is in a month other than the month displayed in the Calendar control. 這個屬性是唯讀的。This property is read-only.

IsSelectable

取得或設定值,指出這個類別的執行個體所代表的日期是否在 Calendar 控制項中可被選取。Gets or sets a value that indicates whether the date represented by an instance of this class can be selected in the Calendar control.

IsSelected

取得值,指出這個類別的執行個體所代表的日期是否在 Calendar 控制項中被選取。Gets a value that indicates whether the date represented by an instance of this class is selected in the Calendar control. 這個屬性是唯讀的。This property is read-only.

IsToday

取得值,指出這個類別的執行個體所代表的日期是否是 TodaysDate 控制項之 Calendar 屬性所指定的相同日期。Gets a value that indicates whether the date represented by an instance of this class is the same date specified by the TodaysDate property of the Calendar control. 這個屬性是唯讀的。This property is read-only.

IsWeekend

取得值,指出這個類別的執行個體所代表的日期是否為星期六或星期日。Gets a value that indicates whether the date represented by an instance of this class is a either Saturday or Sunday. 這個屬性是唯讀的。This property is read-only.

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets 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)

適用於

另請參閱