Partager via


DataList.RenderContents(HtmlTextWriter) Méthode

Définition

Génère le rendu des éléments de liste dans le contrôle DataList.

protected:
 override void RenderContents(System::Web::UI::HtmlTextWriter ^ writer);
protected public:
 override void RenderContents(System::Web::UI::HtmlTextWriter ^ writer);
protected override void RenderContents (System.Web.UI.HtmlTextWriter writer);
protected internal override void RenderContents (System.Web.UI.HtmlTextWriter writer);
override this.RenderContents : System.Web.UI.HtmlTextWriter -> unit
Protected Overrides Sub RenderContents (writer As HtmlTextWriter)
Protected Friend Overrides Sub RenderContents (writer As HtmlTextWriter)

Paramètres

writer
HtmlTextWriter

HtmlTextWriter qui représente le flux de sortie utilisé pour restituer le contenu HTML sur le client.

Exemples

L’exemple de code suivant montre comment remplacer la RenderContents méthode dans un contrôle serveur personnalisé afin que le texte précède l’objet DataList .

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet" Assembly="Samples.AspNet.CS" %>
<%@ 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>Custom DataList - RenderContents - C# Example</title>
        <script runat="server">
          private void Page_Load(object sender, System.EventArgs e)
          {
        // Create sample data for the DataList control.
        System.Data.DataTable dt = new System.Data.DataTable();
        System.Data.DataRow dr;
        dt.Columns.Add(new System.Data.DataColumn("Column1", typeof(String)));
        
        dr = dt.NewRow();
        dr[0] = "Hello";
        dt.Rows.Add(dr);
        
        dr = dt.NewRow();
        dr[0] = "DataList";
        dt.Rows.Add(dr);
        
        dr = dt.NewRow();
        dr[0] = "World";
        dt.Rows.Add(dr);

        // Show the DataTable values in the DataList.
              DataList1.DataSource = dt;
        DataList1.DataBind();
        }        
        </script>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom DataList - RenderContents - C# Example</h3>

            <aspSample:CustomDataListRenderContents id="DataList1" runat="server" 
                BorderColor="#999999" BorderStyle="None" BackColor="White" CellPadding="3" 
                GridLines="Vertical" BorderWidth="1px" Width="100px">
        
          <HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#000084" />
          <HeaderTemplate>
              <asp:Label id="Label1" runat="server">Column1</asp:Label>
          </HeaderTemplate>

          <ItemStyle ForeColor="Black" BackColor="#EEEEEE" />
          <ItemTemplate>
              <asp:Label id="Label2" runat="server"><%# DataBinder.Eval(Container.DataItem, "Column1") %></asp:Label>
          </ItemTemplate>

          <AlternatingItemStyle BackColor="#DCDCDC" />
          <AlternatingItemTemplate>
              <asp:Label id="Label3" runat="server"><%# DataBinder.Eval(Container.DataItem, "Column1") %></asp:Label>
          </AlternatingItemTemplate>
          
      </aspSample:CustomDataListRenderContents>
        </form>
    </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ 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>Custom DataList - RenderContents - VB.NET Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">
      <h3>Custom DataList - RenderContents - VB.NET Example</h3>
      <aspSample:CustomDataListRenderContents id="DataList1" runat="server" />
    </form>
  </body>
</html>
using System.Web;
using System.Security.Permissions;

namespace Samples.AspNet
{
    [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
    public sealed class CustomDataListRenderContents : System.Web.UI.WebControls.DataList
    {
        protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
        {
            // Place some text before the DataList.
            writer.Write("Here is some text from the RenderContent method.<br>");

            // Call the base RenderContents method.
            base.RenderContents(writer);
        }
    }
}
Imports System.Web
Imports System.Security.Permissions

Namespace Samples.AspNet.VB.Controls
    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public NotInheritable Class CustomDataListRenderContents
        Inherits System.Web.UI.WebControls.DataList

        Protected Overrides Sub RenderContents(ByVal writer As System.Web.UI.HtmlTextWriter)

            ' Place some text before the DataList.
            writer.Write("Here is some text from the RenderContent method.<br>")

            ' Call the base RenderContents method.
            MyBase.RenderContents(writer)
        End Sub
    End Class
End Namespace

Remarques

La RenderContents méthode est utilisée principalement par les développeurs de contrôles, lors de la DataList dérivation d’un contrôle personnalisé du contrôle.

La RenderContents méthode affiche le contenu interne du DataList contrôle, y compris les contrôles contenus DataListItem .

S’applique à