DataList.FooterTemplate Propriedade
Definição
public:
virtual property System::Web::UI::ITemplate ^ FooterTemplate { System::Web::UI::ITemplate ^ get(); void set(System::Web::UI::ITemplate ^ value); };
[System.ComponentModel.Browsable(false)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
[System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.DataListItem))]
public virtual System.Web.UI.ITemplate FooterTemplate { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.DataListItem))>]
member this.FooterTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property FooterTemplate As ITemplate
Valor da propriedade
Um objeto ITemplate que contém o modelo da seção de rodapé do controle DataList.A ITemplate object that contains the template for the footer section of the DataList control. O valor padrão é null.The default value is null.
- Atributos
Exemplos
O exemplo de código a seguir demonstra como usar a FooterTemplate propriedade para controlar o conteúdo da seção de rodapé do DataList controle.The following code example demonstrates how to use the FooterTemplate property to control the contents of the footer section of the DataList control.
Observação
O exemplo de código a seguir usa o modelo de código de arquivo único e pode não funcionar corretamente se copiado diretamente para um arquivo code-behind.The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. Este exemplo de código deve ser copiado em um arquivo de texto vazio que tenha uma extensão. aspx.This code sample must be copied into an empty text file that has an .aspx extension. Para obter mais informações sobre o modelo de código Web Forms, consulte modelo de código de página do ASP.NET Web Forms.For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model.
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
<!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" >
<script runat="server">
ICollection CreateDataSource()
{
// Create sample data for the DataList control.
DataTable dt = new DataTable();
DataRow dr;
// Define the columns of the table.
dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
dt.Columns.Add(new DataColumn("StringValue", typeof(String)));
dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));
dt.Columns.Add(new DataColumn("ImageValue", typeof(String)));
// Populate the table with sample values.
for (int i = 0; i < 9; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "Description for item " + i.ToString();
dr[2] = 1.23 * (i + 1);
dr[3] = "Image" + i.ToString() + ".jpg";
dt.Rows.Add(dr);
}
DataView dv = new DataView(dt);
return dv;
}
void Page_Load(Object sender, EventArgs e)
{
// Load sample data only once, when the page is first loaded.
if (!IsPostBack)
{
ItemsList.DataSource = CreateDataSource();
ItemsList.DataBind();
}
}
void Selection_Change(Object sender, EventArgs e)
{
// Set the background color for the heading and footer sections
// of the DataList control.
ItemsList.HeaderStyle.BackColor =
System.Drawing.Color.FromName(List.SelectedItem.Value);
ItemsList.FooterStyle.BackColor =
System.Drawing.Color.FromName(List.SelectedItem.Value);
}
</script>
<head runat="server">
<title>DataList HeaderStyle and FooterStyle Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>DataList HeaderStyle and FooterStyle Example</h3>
Select a background color for the header and footer sections.
<br /><br />
<asp:DataList id="ItemsList"
BorderColor="black"
CellPadding="5"
CellSpacing="5"
RepeatDirection="Vertical"
RepeatLayout="Table"
RepeatColumns="3"
ShowFooter="True"
runat="server">
<HeaderStyle BackColor="White">
</HeaderStyle>
<FooterStyle BackColor="White">
</FooterStyle>
<AlternatingItemStyle BackColor="Gainsboro">
</AlternatingItemStyle>
<HeaderTemplate>
List of items
</HeaderTemplate>
<FooterTemplate>
<asp:Image id="FooterImage"
GenerateEmptyAlternateText='true'
ImageUrl='FooterImage.jpg'
runat="server"/>
</FooterTemplate>
<ItemTemplate>
Description: <br />
<%# DataBinder.Eval(Container.DataItem, "StringValue") %>
<br />
Price: <%# DataBinder.Eval(Container.DataItem, "CurrencyValue", "{0:c}") %>
<br />
<asp:Image id="ProductImage"
AlternatingText='<%# DataBinder.Eval(Container.DataItem, "StringValue") %>'
ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImageValue") %>'
runat="server"/>
</ItemTemplate>
</asp:DataList>
<hr />
Header and footer BackColor: <br />
<asp:DropDownList id="List"
AutoPostBack="True"
OnSelectedIndexChanged="Selection_Change"
runat="server">
<asp:ListItem Selected="True" Value="White"> White </asp:ListItem>
<asp:ListItem Value="Silver"> Silver </asp:ListItem>
<asp:ListItem Value="DarkGray"> Dark Gray </asp:ListItem>
<asp:ListItem Value="Khaki"> Khaki </asp:ListItem>
<asp:ListItem Value="DarkKhaki"> Dark Khaki </asp:ListItem>
</asp:DropDownList>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
<!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" >
<script runat="server">
Function CreateDataSource() As ICollection
' Create sample data for the DataList control.
Dim dt As DataTable = New DataTable()
dim dr As DataRow
' Define the columns of the table.
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn("ImageValue", GetType(String)))
' Populate the table with sample values.
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Description for item " & i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = "Image" & i.ToString() & ".jpg"
dt.Rows.Add(dr)
Next i
Dim dv As DataView = New DataView(dt)
Return dv
End Function
Sub Page_Load(sender As Object, e As EventArgs)
' Load sample data only once, when the page is first loaded.
If Not IsPostBack Then
ItemsList.DataSource = CreateDataSource()
ItemsList.DataBind()
End If
End Sub
Sub Selection_Change(sender As Object, e As EventArgs)
' Set the background color for the heading and footer sections
' of the DataList control.
ItemsList.HeaderStyle.BackColor = _
System.Drawing.Color.FromName(List.SelectedItem.Value)
ItemsList.FooterStyle.BackColor = _
System.Drawing.Color.FromName(List.SelectedItem.Value)
End Sub
</script>
<head runat="server">
<title>DataList HeaderStyle and FooterStyle Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>DataList HeaderStyle and FooterStyle Example</h3>
Select a background color for the header and footer sections.
<br /><br />
<asp:DataList id="ItemsList"
BorderColor="black"
CellPadding="5"
CellSpacing="5"
RepeatDirection="Vertical"
RepeatLayout="Table"
RepeatColumns="3"
ShowFooter="True"
runat="server">
<HeaderStyle BackColor="White">
</HeaderStyle>
<FooterStyle BackColor="White">
</FooterStyle>
<AlternatingItemStyle BackColor="Gainsboro">
</AlternatingItemStyle>
<HeaderTemplate>
List of items
</HeaderTemplate>
<FooterTemplate>
<asp:Image id="FooterImage"
ImageUrl='FooterImage.jpg'
GenerateEmptyAlternateText='true'
runat="server"/>
</FooterTemplate>
<ItemTemplate>
Description: <br />
<%# DataBinder.Eval(Container.DataItem, "StringValue") %>
<br />
Price: <%# DataBinder.Eval(Container.DataItem, "CurrencyValue", "{0:c}") %>
<br />
<asp:Image id="ProductImage"
AlternatingText='<%# DataBinder.Eval(Container.DataItem, "StringValue") %>'
ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImageValue") %>'
runat="server"/>
</ItemTemplate>
</asp:DataList>
<hr />
Header and footer BackColor: <br />
<asp:DropDownList id="List"
AutoPostBack="True"
OnSelectedIndexChanged="Selection_Change"
runat="server">
<asp:ListItem Selected="True" Value="White"> White </asp:ListItem>
<asp:ListItem Value="Silver"> Silver </asp:ListItem>
<asp:ListItem Value="DarkGray"> Dark Gray </asp:ListItem>
<asp:ListItem Value="Khaki"> Khaki </asp:ListItem>
<asp:ListItem Value="DarkKhaki"> Dark Khaki </asp:ListItem>
</asp:DropDownList>
</form>
</body>
</html>
Comentários
Use a FooterTemplate propriedade para controlar o conteúdo da seção de rodapé.Use the FooterTemplate property to control the contents of the footer section. A aparência da seção de rodapé é controlada pela FooterStyle propriedade.The appearance of the footer section is controlled by the FooterStyle property.
Observação
A ShowFooter propriedade deve ser definida como true para que essa propriedade seja visível.The ShowFooter property must be set to true for this property to be visible.
A HeaderStyle Propriedade do DataList controle herda as configurações de estilo da ControlStyle propriedade.The HeaderStyle property of the DataList control inherits the style settings of the ControlStyle property. Por exemplo, se você especificar uma fonte vermelha para a ControlStyle propriedade, a HeaderStyle propriedade também terá uma fonte vermelha.For example, if you specify a red font for the ControlStyle property, the HeaderStyle property will also have a red font. Isso permite que você forneça uma aparência comum para o controle definindo uma única propriedade de estilo.This allows you to provide a common appearance for the control by setting a single style property. Você pode substituir as configurações de estilo herdadas definindo a HeaderStyle propriedade.You can override the inherited style settings by setting the HeaderStyle property. Por exemplo, você pode especificar uma fonte azul para a HeaderStyle propriedade, substituindo a fonte vermelha especificada na ControlStyle propriedade.For example, you can specify a blue font for the HeaderStyle property, overriding the red font specified in the ControlStyle property.
Para especificar um modelo para a seção de rodapé, coloque as <FooterTemplate> marcas entre as marcas de abertura e de fechamento do DataList controle.To specify a template for the footer section, place the <FooterTemplate> tags between the opening and closing tags of the DataList control. Em seguida, você pode listar o conteúdo do modelo entre as marcas de abertura e de fechamento <FooterTemplate> .You can then list the contents of the template between the opening and closing <FooterTemplate> tags.
Cuidado
Esse controle pode ser usado para exibir a entrada do usuário, que pode incluir script de cliente mal-intencionado.This control can be used to display user input, which might include malicious client script. Verifique todas as informações enviadas de um cliente para script executável, instruções SQL ou outro código antes de exibi-lo em seu aplicativo.Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. Você pode usar controles de validação para verificar a entrada do usuário antes de exibir o texto de entrada em um controle.You can use validation controls to verify user input before displaying the input text in a control. O ASP.NET fornece um recurso de validação de solicitação de entrada para bloquear o script e o HTML na entrada do usuário.ASP.NET provides an input request validation feature to block script and HTML in user input. Para obter mais informações, consulte protegendo controles padrão, como proteger contra explorações de script em um aplicativo Web aplicando codificação HTML a cadeias de caracterese validando a entrada do usuário no páginas da Web do ASP.net.For more information, see Securing Standard Controls, How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings, and Validating User Input in ASP.NET Web Pages.
Aplica-se a
Confira também
- FooterStyle
- ShowFooter
- ITemplate
- Protegendo controles padrãoSecuring Standard Controls
- Como: proteger contra explorações de script em um aplicativo Web aplicando codificação HTML a cadeias de caracteresHow to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings
- Introdução à validação de entrada do usuário no Páginas da Web do ASP.NETIntroduction to Validating User Input in ASP.NET Web Pages
- Modelo de código de página da Web ASP.NETASP.NET Web Page Code Model