DayRenderEventArgs.Cell プロパティ

定義

TableCell コントロールに表示されるセルを表す Calendar オブジェクトを取得します。

public:
 property System::Web::UI::WebControls::TableCell ^ Cell { System::Web::UI::WebControls::TableCell ^ get(); };
public System.Web.UI.WebControls.TableCell Cell { get; }
member this.Cell : System.Web.UI.WebControls.TableCell
Public ReadOnly Property Cell As TableCell

プロパティ値

TableCell に表示するセルを表す Calendar

次のコード例では、 プロパティを Cell 使用して、表示される月の日数の背景色を黄色にプログラムで変更する方法を示します。 また、 プロパティのコレクションにコントロールを追加System.Web.UI.LiteralControlして、セルのCell内容をカスタマイズするControl.Controls方法も示します。

<%@ 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>DayRender Event Example</title>
<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 />Birthday"));

      }

   </script>
 
</head>
 
<body>
 
   <form id="form1" 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" %>

<!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>DayRender Event Example</title>
<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("<br />" & "Birthday"))
        End If 
    End Sub 'DayRender
  </script>
 
</head>
 
<body>
 
   <form id="form1" runat="server">

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

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

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

注釈

コントロールに Cell レンダリングされるセルをプログラムで制御するには、 プロパティを Calendar 使用します。

プロパティのコレクションにコントロールを動的に追加することで、セルの内容をControl.ControlsCellカスタマイズできます。

Note

コントロールの DayRender レンダリング中 Calendar にイベントが発生するため、 などの LinkButtonイベントを発生させることができるコントロールを追加することはできません。 、、、 などのLiteralControlLabelImageHyperLink静的コントロールのみを追加できます。

適用対象

こちらもご覧ください