DayRenderEventArgs.Cell プロパティ
アセンブリ: System.Web (system.web.dll 内)


Cell プロパティを使用して、Calendar コントロールに表示されるセルをプログラムにより制御します。
Cell プロパティの Control.Controls コレクションにコントロールを動的に追加することにより、セルの内容をカスタマイズできます。
![]() |
---|
DayRender イベントは Calendar コントロールの表示中に発生するため、ユーザーはイベントを発生させる可能性がある LinkButton などのコントロールを追加できません。追加できるのは LiteralControl、Label、Image、HyperLink などのスタティック コントロールだけです。 |

Cell プロパティを使用して、表示された月の日付の背景色をプログラムにより黄色に変更するコード例を次に示します。Cell プロパティの Control.Controls コレクションに 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("<br>" & "Birthday")) 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>Birthday")); } </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>

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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- DayRenderEventArgs.Cell プロパティのページへのリンク