CalendarDay クラス

Calendar コントロールの日付を表します。

この型のすべてのメンバの一覧については、CalendarDay メンバ を参照してください。

System.Object
   System.Web.UI.WebControls.CalendarDay

Public Class CalendarDay
[C#]
public class CalendarDay
[C++]
public __gc class CalendarDay
[JScript]
public class CalendarDay

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

Calendar コントロールの日付を示す CalendarDay オブジェクト。 DayRender イベント ハンドラのこのクラスを使用して、 Calendar コントロールに表示される日付のプロパティにプログラムによりアクセスできます。プログラムによるアクセスにより、日付のプロパティ (日付を選択できるかどうか、日付が選択されているかどうか、現在の日付、週末の日付など) を確認し、日付の表示形式や動作をプログラムにより制御できます。

CalendarDay のインスタンスの初期プロパティ値の一覧については、 CalendarDay コンストラクタのトピックを参照してください。

使用例

[Visual Basic, C#, JScript] CalendarDay オブジェクトのプロパティを使用して、 DayRender イベントで表示される日付が表示された月内の日付であり、土曜日や日曜日でないことを確認する方法を次の例に示します。これらの日付は黄色で表示されます。 DayRender イベント ハンドラに渡される DayRenderEventArgs オブジェクトの Day プロパティは、 CalendarDay オブジェクトです。

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

<html>
<head>

   <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 runat="server">
 
      <asp:Calendar id="calendar1" runat="server"
           WeekendDayStyle-BackColor="gray"
           OnDayRender="DayRender"/>
                   
   </form>
         
</body>
</html>
   

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
<head>

   <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 runat="server">
 
      <asp:Calendar id="calendar1" runat="server"
           WeekendDayStyle-BackColor="gray"
           OnDayRender="DayRender"/>
                   
   </form>
         
</body>
</html>
   

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>
<head>

   <script language="JScript" runat="server">

      function DayRender(source : Object, e : DayRenderEventArgs) 
      {
      
         if (!e.Day.IsOtherMonth && !e.Day.IsWeekend)
            e.Cell.BackColor=System.Drawing.Color.Yellow;
      
      }

   </script>
 
</head>
 
<body>
 
   <form runat="server">
 
      <asp:Calendar id="calendar1" runat="server"
           WeekendDayStyle-BackColor="gray"
           OnDayRender="DayRender"/>
                   
   </form>
         
</body>
</html>
   

[Visual Basic] 
<%@ 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>
   

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>

   <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 runat="server">

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

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

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

[C++] C++ のサンプルはありません。Visual Basic、C#、および JScript のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Web.UI.WebControls

プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Web (System.Web.dll 内)

参照

CalendarDay メンバ | System.Web.UI.WebControls 名前空間 | Calendar | DayRender | DayRenderEventArgs | Day