DetailsView.FooterRow 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 DetailsViewRow 物件,其表示 DetailsView 控制項中的頁尾資料列。
public:
virtual property System::Web::UI::WebControls::DetailsViewRow ^ FooterRow { System::Web::UI::WebControls::DetailsViewRow ^ get(); };
[System.ComponentModel.Browsable(false)]
public virtual System.Web.UI.WebControls.DetailsViewRow FooterRow { get; }
[<System.ComponentModel.Browsable(false)>]
member this.FooterRow : System.Web.UI.WebControls.DetailsViewRow
Public Overridable ReadOnly Property FooterRow As DetailsViewRow
屬性值
DetailsViewRow,表示 DetailsView 控制項中的頁尾資料列。
- 屬性
範例
下列程式碼範例示範如何使用 FooterRow 屬性,在 事件期間 ItemCreated 存取 控制項的 DetailsView 頁尾資料列。 然後,自訂 Label 頁尾資料列內的控制項會以目前的頁碼更新。
<%@ Page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void CustomerDetailView_DataBound(object sender,
EventArgs e)
{
// Get the footer row.
DetailsViewRow footerRow = CustomerDetailView.FooterRow;
// Get the Label control that displays the current page
// information from the footer row.
Label pageNum =
(Label)footerRow.Cells[0].FindControl("PageNumberLabel");
if (pageNum != null)
{
// Update the Label control with the current page number.
int page = CustomerDetailView.DataItemIndex + 1;
pageNum.Text = "Page " + page.ToString();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DetailsView FooterTemplate Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>DetailsView FooterTemplate Example</h3>
<asp:detailsview id="CustomerDetailView"
datasourceid="DetailsViewSource"
datakeynames="CustomerID"
autogeneraterows="true"
allowpaging="true"
runat="server"
OnDataBound="CustomerDetailView_DataBound">
<headerstyle backcolor="Navy"
forecolor="White"/>
<pagersettings Mode="NextPreviousFirstLast"/>
<FooterTemplate>
<table width="100%">
<tr>
<td align="left">
<asp:Image id="LogoImage"
AlternateText="Our logo"
imageurl="~\images\Logo.jpg"
runat="server"/>
</td>
<td align="right" valign="bottom">
<asp:Label id="PageNumberLabel"
font-size="9"
forecolor="DodgerBlue"
runat="server"/>
</td>
</tr>
</table>
</FooterTemplate>
</asp:detailsview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the web.config file. -->
<asp:SqlDataSource ID="DetailsViewSource" runat="server"
ConnectionString=
"<%$ ConnectionStrings:NorthWindConnectionString%>"
InsertCommand="INSERT INTO [Customers]([CustomerID],
[CompanyName], [Address], [City], [PostalCode], [Country])
VALUES (@CustomerID, @CompanyName, @Address, @City,
@PostalCode, @Country)"
SelectCommand="Select [CustomerID], [CompanyName],
[Address], [City], [PostalCode], [Country] From
[Customers]">
</asp:SqlDataSource>
</form>
</body>
</html>
<%@ Page language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub CustomerDetailView_DataBound(ByVal sender As Object, _
ByVal e As EventArgs)
' Get the footer row.
Dim footerRow As DetailsViewRow = CustomerDetailView.FooterRow
' Get the Label control that displays the current page
' information from the footer row.
Dim pageNum As Label = _
CType(footerRow.Cells(0).FindControl("PageNumberLabel"), Label)
If pageNum IsNot Nothing Then
' Update the Label control with the current page number.
Dim page As Integer = CustomerDetailView.DataItemIndex + 1
pageNum.Text = "Page " + page.ToString()
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DetailsView FooterTemplate Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>DetailsView FooterTemplate Example</h3>
<asp:detailsview id="CustomerDetailView"
datasourceid="DetailsViewSource"
datakeynames="CustomerID"
autogeneraterows="true"
allowpaging="true"
runat="server"
OnDataBound="CustomerDetailView_DataBound">
<headerstyle backcolor="Navy"
forecolor="White"/>
<pagersettings Mode="NextPreviousFirstLast"/>
<FooterTemplate>
<table width="100%">
<tr>
<td align="left">
<asp:Image id="LogoImage"
AlternateText="Our logo"
imageurl="~\images\Logo.jpg"
runat="server"/>
</td>
<td align="right" valign="bottom">
<asp:Label id="PageNumberLabel"
font-size="9"
forecolor="DodgerBlue"
runat="server"/>
</td>
</tr>
</table>
</FooterTemplate>
</asp:detailsview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the web.config file. -->
<asp:SqlDataSource ID="DetailsViewSource" runat="server"
ConnectionString=
"<%$ ConnectionStrings:NorthWindConnectionString%>"
InsertCommand="INSERT INTO [Customers]([CustomerID],
[CompanyName], [Address], [City], [PostalCode], [Country])
VALUES (@CustomerID, @CompanyName, @Address, @City,
@PostalCode, @Country)"
SelectCommand="Select [CustomerID], [CompanyName],
[Address], [City], [PostalCode], [Country] From
[Customers]">
</asp:SqlDataSource>
</form>
</body>
</html>
備註
設定 或 FooterTemplate 屬性時 FooterText ,頁尾列會顯示在控制項底部 DetailsView 。 FooterRow使用 屬性,以程式設計方式存取 DetailsViewRow 代表頁尾資料列的物件。
注意
只有在 FooterRow 控制項在 事件中 ItemCreated 建立頁尾資料列之後 DetailsView ,才能使用 屬性。
當您需要以程式設計方式動作頁尾資料列時,例如新增自訂內容時,通常會使用這個屬性。 任何修改FooterRow後,就必須執行屬性DetailsView控制項已轉譯,否則DetailsView控制項將會覆寫任何變更。
若要控制頁尾資料列的樣式,請使用 FooterStyle 屬性。