DataList.FooterStyle 屬性

定義

取得 DataList 控制項頁尾區段的樣式屬性。

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 控制項頁尾區段的樣式屬性。 預設值為空白的 TableItemStyle 物件。

屬性

範例

下列程式碼範例示範如何使用 FooterStyle 屬性來指定 控制項頁尾區段的 DataList 自訂背景色彩。

注意

下列程式碼範例會使用單一檔案程式碼模型,如果直接複製到程式碼後置檔案,可能無法正常運作。 此程式碼範例必須複製到副檔名為 .aspx 的空白文字檔。 如需Web Form程式碼模型的詳細資訊,請參閱ASP.NET Web Forms頁碼模型


<%@ 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 自訂樣式。 可調整的常見樣式屬性包括前景色彩、背景色彩、字型,以及儲存格內的內容對齊方式。 提供不同的樣式可增強控制項的外觀 DataList

控制項 FooterStyleDataList 屬性會繼承 屬性的 ControlStyle 樣式設定。 例如,如果您為 屬性指定紅色字 ControlStyle 型,屬性 FooterStyle 也會有紅色字型。 這可讓您藉由設定單一樣式屬性來提供控制項的通用外觀。 您可以藉由設定 屬性來覆寫繼承的 FooterStyle 樣式設定。 例如,您可以指定屬性的 FooterStyle 藍色字型,覆寫 屬性中指定的 ControlStyle 紅色字型。

若要指定頁尾區段的自訂樣式,請將 <FooterStyle> 標記放在控制項的開頭和結束記號 DataList 之間。 然後,您可以在開頭 <FooterStyle> 標記內列出樣式屬性。

注意

屬性 ShowFooter 必須設定為 true ,這個屬性才能顯示。

適用於

另請參閱