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 элемента управления в Control.Controls коллекцию Cell свойства .

<%@ 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.Controls коллекцию Cell свойства .

Примечание

DayRender Так как событие возникает во время Calendar отрисовки элемента управления, нельзя добавить элемент управления, который также может вызывать событие, например LinkButton. Можно добавлять только статические элементы управления, такие как LiteralControl, Label, Imageи HyperLink.

Применяется к

См. также раздел