DataList.FooterStyle 属性
定义
public:
virtual property System::Web::UI::WebControls::TableItemStyle ^ FooterStyle { System::Web::UI::WebControls::TableItemStyle ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public virtual System.Web.UI.WebControls.TableItemStyle FooterStyle { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.FooterStyle : System.Web.UI.WebControls.TableItemStyle
Public Overridable ReadOnly Property FooterStyle As TableItemStyle
属性值
一个 TableItemStyle 对象,该对象包含 DataList 控件的脚注部分的样式属性。A TableItemStyle object that contains the style properties for the footer section of the DataList control. 默认值是一个空 TableItemStyle 对象。The default value is an empty TableItemStyle object.
- 属性
示例
下面的代码示例演示如何使用 FooterStyle 属性为控件的脚注部分指定自定义背景色 DataList 。The following code example demonstrates how to use the FooterStyle property to specify a custom background color for the footer section of the DataList control.
备注
下面的代码示例使用单文件代码模型,如果直接复制到代码隐藏文件中,则可能无法正常工作。The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. 必须将此代码示例复制到扩展名为 .aspx 的空文本文件中。This code sample must be copied into an empty text file that has an .aspx extension. 有关 Web 窗体代码模型的详细信息,请参阅 ASP.NET Web 窗体页代码模型。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>
注解
使用此属性为控件的脚注部分提供自定义样式 DataList 。Use this property to provide a custom style for the footer section of the DataList control. 可以调整的常见样式属性包括单元中的前景色、背景色、字体和内容对齐方式。Common style attributes that can be adjusted include foreground color, background color, font, and content alignment within the cell. 提供不同的样式可增强控件的外观 DataList 。Providing a different style enhances the appearance of the DataList control.
FooterStyle控件的属性 DataList 继承属性的样式设置 ControlStyle 。The FooterStyle property of the DataList control inherits the style settings of the ControlStyle property. 例如,如果为属性指定红色字体 ControlStyle ,则 FooterStyle 属性也将具有红色字体。For example, if you specify a red font for the ControlStyle property, the FooterStyle property will also have a red font. 这使您可以通过设置单个样式属性来为控件提供常见的外观。This allows you to provide a common appearance for the control by setting a single style property. 可以通过设置属性来重写继承的样式设置 FooterStyle 。You can override the inherited style settings by setting the FooterStyle property. 例如,您可以为属性指定一个蓝色字体 FooterStyle ,并覆盖在属性中指定的红色字体 ControlStyle 。For example, you can specify a blue font for the FooterStyle property, overriding the red font specified in the ControlStyle property.
若要为脚注部分指定自定义样式,请将 <FooterStyle> 标记放置在控件的开始标记和结束标记之间 DataList 。To specify a custom style for the footer section, place the <FooterStyle> tags between the opening and closing tags of the DataList control. 然后,你可以在开始标记中列出样式属性 <FooterStyle> 。You can then list the style attributes within the opening <FooterStyle> tag.
备注
ShowFooter属性必须设置为, true 此属性才可见。The ShowFooter property must be set to true for this property to be visible.