DayRenderEventArgs.Cell Propriété

Définition

Obtient l'objet TableCell représentant la cellule rendue dans le contrôle 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

Valeur de propriété

TableCell qui représente la cellule rendue dans Calendar.

Exemples

L’exemple de code suivant montre comment utiliser la Cell propriété pour modifier par programme la couleur d’arrière-plan des jours du mois affiché en jaune. Il montre également comment personnaliser le contenu d’une cellule en ajoutant un System.Web.UI.LiteralControl contrôle à la Control.Controls collection de la Cell propriété .

<%@ 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>

Remarques

Utilisez la Cell propriété pour contrôler par programmation la cellule affichée dans le Calendar contrôle.

Vous pouvez personnaliser le contenu d’une cellule en ajoutant dynamiquement des contrôles à la Control.Controls collection de la Cell propriété .

Notes

Étant donné que l’événement DayRender est déclenché pendant le rendu du Calendar contrôle, vous ne pouvez pas ajouter un contrôle qui peut également déclencher un événement, tel que LinkButton. Vous pouvez ajouter uniquement des contrôles statiques, tels que LiteralControl, Label, Imageet HyperLink.

S’applique à

Voir aussi