DetailsView.PagerStyle 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 TableItemStyle 物件的參考,可以讓您設定 DetailsView 控制項中頁面巡覽列的外觀。
public:
property System::Web::UI::WebControls::TableItemStyle ^ PagerStyle { System::Web::UI::WebControls::TableItemStyle ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.TableItemStyle PagerStyle { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.PagerStyle : System.Web.UI.WebControls.TableItemStyle
Public ReadOnly Property PagerStyle As TableItemStyle
屬性值
TableItemStyle 的參考,表示 DetailsView 控制項中頁面巡覽列的樣式。
- 屬性
範例
下列程式碼範例示範如何使用 PagerStyle 屬性來指定頁面巡覽列的字型和樣式設定。
<%@ 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 pager row.
DetailsViewRow pagerRow = CustomerDetailView.BottomPagerRow;
// Get the Label controls that display the current page information
// from the pager row.
Label pageNum = (Label)pagerRow.Cells[0].FindControl("PageNumberLabel");
Label totalNum = (Label)pagerRow.Cells[0].FindControl("TotalPagesLabel");
if ((pageNum != null) && (totalNum != null))
{
// Update the Label controls with the current page values.
int page = CustomerDetailView.DataItemIndex + 1;
int count = CustomerDetailView.DataItemCount;
pageNum.Text = page.ToString();
totalNum.Text = count.ToString();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DetailsView PagerTemplate Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>DetailsView PagerTemplate Example</h3>
<!-- Notice that the LinkButton controls in the pager -->
<!-- template have their CommandName properties set. -->
<!-- The DetailsView control automatically recognizes -->
<!-- certain command names and performs the appropriate -->
<!-- operation. In this example, the CommandName -->
<!-- properties are set "Page" and the CommandArgument -->
<!-- properties are set to "Next" and "Prev", which -->
<!-- causes the DetailsView control to navigate to the -->
<!-- next and previous record, respectively. -->
<asp:detailsview id="CustomerDetailView"
datasourceid="DetailsViewSource"
autogeneraterows="true"
allowpaging="true"
runat="server" OnDataBound="CustomerDetailView_DataBound">
<headerstyle backcolor="Navy"
forecolor="White"/>
<pagerstyle VerticalAlign="Bottom" />
<pagertemplate>
<table width="100%">
<tr>
<td>
<asp:LinkButton id="PreviousButton"
text="<"
CommandName="Page"
CommandArgument="Prev"
runat="Server"/>
<asp:LinkButton id="NextButton"
text=">"
CommandName="Page"
CommandArgument="Next"
runat="Server"/>
</td>
<td align="right">
Page <asp:Label id="PageNumberLabel" runat="server" />
of <asp:Label id="TotalPagesLabel" runat="server" />
</td>
</tr>
</table>
</pagertemplate>
</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 pager row.
Dim pagerRow As DetailsViewRow = CustomerDetailView.BottomPagerRow
' Get the Label controls that display the current page information
' from the pager row.
Dim pageNum As Label = CType(pagerRow.Cells(0).FindControl("PageNumberLabel"), Label)
Dim totalNum As Label = CType(pagerRow.Cells(0).FindControl("TotalPagesLabel"), Label)
If (pageNum IsNot Nothing) And (totalNum IsNot Nothing) Then
' Update the Label controls with the current page values.
Dim page As Integer = CustomerDetailView.DataItemIndex + 1
Dim count As Integer = CustomerDetailView.DataItemCount
pageNum.Text = page.ToString()
totalNum.Text = count.ToString()
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DetailsView PagerTemplate Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>DetailsView PagerTemplate Example</h3>
<!-- Notice that the LinkButton controls in the pager -->
<!-- template have their CommandName properties set. -->
<!-- The DetailsView control automatically recognizes -->
<!-- certain command names and performs the appropriate -->
<!-- operation. In this example, the CommandName -->
<!-- properties are set "Page" and the CommandArgument -->
<!-- properties are set to "Next" and "Prev", which -->
<!-- causes the DetailsView control to navigate to the -->
<!-- next and previous record, respectively. -->
<asp:detailsview id="CustomerDetailView"
datasourceid="DetailsViewSource"
autogeneraterows="true"
allowpaging="true"
runat="server" OnDataBound="CustomerDetailView_DataBound">
<headerstyle backcolor="Navy"
forecolor="White"/>
<pagerstyle VerticalAlign="Bottom" />
<pagertemplate>
<table width="100%">
<tr>
<td>
<asp:LinkButton id="PreviousButton"
text="<"
CommandName="Page"
CommandArgument="Prev"
runat="Server"/>
<asp:LinkButton id="NextButton"
text=">"
CommandName="Page"
CommandArgument="Next"
runat="Server"/>
</td>
<td align="right">
Page <asp:Label id="PageNumberLabel" runat="server" />
of <asp:Label id="TotalPagesLabel" runat="server" />
</td>
</tr>
</table>
</pagertemplate>
</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>
備註
PagerStyle使用 屬性來控制 控制項中 DetailsView 呼叫器資料列的外觀。 藉由將 屬性 true
設定 AllowPaging 為) ,並包含可讓使用者巡覽至控制項中不同頁面的控制項,即可顯示分頁功能 (。 此屬性是唯讀的;不過,您可以設定其傳回之 TableItemStyle 物件的屬性。 屬性可以宣告方式設定在 表單 Property-Subproperty
中,其中 Subproperty
是 物件 (TableItemStyle 的屬性, PagerStyle-ForeColor
例如,) 。 屬性也可以在表單 Property.Subproperty
中以程式設計方式設定,例如, PagerStyle.ForeColor
) (。 一般設定通常包含自訂背景色彩、前景色彩和字型屬性。