Calendar.OnDayRender(TableCell, CalendarDay) 메서드

정의

DayRender 컨트롤의 Calendar 이벤트를 발생시키고 사용자가 DayRender 이벤트에 대한 사용자 지정 처리기를 제공할 수 있도록 합니다.

protected:
 virtual void OnDayRender(System::Web::UI::WebControls::TableCell ^ cell, System::Web::UI::WebControls::CalendarDay ^ day);
protected virtual void OnDayRender (System.Web.UI.WebControls.TableCell cell, System.Web.UI.WebControls.CalendarDay day);
abstract member OnDayRender : System.Web.UI.WebControls.TableCell * System.Web.UI.WebControls.CalendarDay -> unit
override this.OnDayRender : System.Web.UI.WebControls.TableCell * System.Web.UI.WebControls.CalendarDay -> unit
Protected Overridable Sub OnDayRender (cell As TableCell, day As CalendarDay)

매개 변수

cell
TableCell

렌더링할 셀에 대한 정보가 들어 있는 TableCell입니다.

day
CalendarDay

렌더링할 날짜에 대한 정보가 들어 있는 CalendarDay입니다.

예제

다음 코드 예제에는 지정 하 고에 대 한 처리기를 코딩 하는 방법을 보여 줍니다.는 DayRender 이벤트의 배경색을 노란색 표시 된 달의 일 수 있도록 합니다. 셀의 내용을 추가 하 여 사용자 지정 하는 방법을 보여 줍니다는 System.Web.UI.LiteralControl 셀에는 컨트롤입니다.

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

      }

   </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(ChrW(60) & "br" & ChrW(62) & "Holiday"))
            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>
<%@ 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>

설명

에 대 한 데이터 바인딩이 지원 되지 않습니다 하지만 Calendar 컨트롤 이며 콘텐츠를 수정할 수는 개별 날짜 셀 서식 지정 합니다. 컨트롤이 Calendar 웹 페이지에 표시되기 전에 컨트롤을 구성하는 구성 요소를 만들고 어셈블합니다. DayRender 이벤트는 각 날짜의 셀을 Calendar 컨트롤이 만들어집니다. 내용 및 코드에 대 한 이벤트 처리기에서 제공 하 여 만들어질 때 날짜 셀의 서식을 제어할 수 있습니다.는 DayRender 이벤트입니다.

이벤트 처리기는 이벤트 데이터가 포함된 개체를 받 DayRenderEventArgs 습니다. 개체에는 DayRenderEventArgs 날짜 셀의 형식을 프로그래밍 방식으로 제어하는 데 사용할 수 있는 두 가지 속성이 포함되어 있습니다. 속성은 Cell 렌더링되는 셀을 나타내고 속성은 Day 셀에서 렌더링할 날짜를 나타냅니다.

컨트롤을 속성 컬렉션에 동적으로 추가하여 셀 내용을 Cell 사용자 지정할 수도 있습니다Control.Controls.

참고

컨트롤이 DayRender 렌더링되는 동안 Calendar 이벤트가 발생하므로 와 같은 LinkButton이벤트를 발생시키는 컨트롤을 추가할 수 없습니다. , , LabelImageHyperLink및 와 같은 System.Web.UI.LiteralControl정적 컨트롤만 추가할 수 있습니다.

이벤트가 발생하면 대리자를 통해 이벤트 처리기가 호출됩니다. 자세한 내용은 이벤트 처리 및 발생합니다.

또한 OnDayRender 메서드를 사용하면 파생 클래스가 대리자를 연결하지 않고도 이벤트를 처리할 수 있습니다. 이는 파생 클래스에서 이벤트를 처리하는 기본 방법입니다.

상속자 참고

파생 클래스에서 OnDayRender(TableCell, CalendarDay)를 재정의하는 경우 등록된 대리자가 이벤트를 받도록 기본 클래스의 OnDayRender(TableCell, CalendarDay) 메서드를 호출해야 합니다.

적용 대상

추가 정보