Calendar.DayRender イベントとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Calendar.DayRender イベントの意味・解説 

Calendar.DayRender イベント

各日付が Calendar コントロールのコントロール階層で作成されると発生します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Event DayRender As
 DayRenderEventHandler
Dim instance As Calendar
Dim handler As DayRenderEventHandler

AddHandler instance.DayRender, handler
public event DayRenderEventHandler DayRender
public:
event DayRenderEventHandler^ DayRender {
    void add (DayRenderEventHandler^ value);
    void remove (DayRenderEventHandler^ value);
}
/** @event */
public void add_DayRender (DayRenderEventHandler
 value)

/** @event */
public void remove_DayRender (DayRenderEventHandler
 value)
JScript では、イベントは使用できますが、新規に宣言することはできません。
解説解説

このイベントは、各日付が Calendar コントロールのコントロール階層で作成されると発生します。

データ連結は Calendar コントロールではサポートされていませんが、各日付セルの内容と書式は変更できます。Calendar コントロールは、Web ページに表示される前に、構成要素であるコンポーネントを作成してアセンブルします。DayRender イベントは、Calendar コントロールの各日付セルが作成されるときに発生します。DayRender イベントのイベント ハンドラにコードを記述することで、日付セルの作成時にその内容と書式を制御できます。日付セルの内容をカスタマイズする方法の詳細については、OnDayRender のトピックを参照してください。

メモメモ

DayRender イベントは Calendar コントロールの表示中に発生するため、ユーザーはイベントを発生させる可能性がある LinkButton などのコントロールを追加できません。追加できるのは System.Web.UI.LiteralControl、Label、Image、HyperLink などのスタティック コントロールだけです。

イベント処理の詳細については、「イベントとデリゲート」を参照してください。

使用例使用例

DayRender イベントのハンドラを指定およびコード化して、表示された月の日付の背景色を黄色にする方法を次のコード例に示します。このコード例では、セルに System.Web.UI.LiteralControl コントロールを追加して、セルの内容をカスタマイズする方法も示します。

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

   <script language="VB" runat="server">
   
        Sub DayRender(source 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(ChrW(60)
 & "br" & ChrW(62) & "Holiday"))
            End If 
        End Sub 'DayRender 

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

      <h3>DayRender Event Example</h3>
 
      <asp:Calendar id="calendar1" 
                    OnDayRender="DayRender"
                    runat="server">

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

      </asp:Calendar>
                   
   </form>
          
</body>
</html>
   
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>

   <script language="C#" runat="server">
   
      void DayRender(Object source, 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"));

      }

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

      <h3>DayRender Event Example</h3>
 
      <asp:Calendar id="calendar1" 
                    OnDayRender="DayRender"
                    runat="server">

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

      </asp:Calendar>
                   
   </form>
          
</body>
</html>
   
<%@ Page Language="JScript" AutoEventWireup="True" %>
<html>
<head>

   <script language="JScript" runat="server">
   
      function DayRender(source : Object, e : DayRenderEventArgs)
 
      {

         // 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"));

      }

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

      <h3>DayRender Event Example</h3>
 
      <asp:Calendar id="calendar1" 
                    OnDayRender="DayRender"
                    runat="server">

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

      </asp:Calendar>
                   
   </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>
   
<%@ 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>
   
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「Calendar.DayRender イベント」の関連用語

Calendar.DayRender イベントのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Calendar.DayRender イベントのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS