更新:2007 年 11 月
命名空間:
System.Web.UI.WebControls 組件:
System.Web.Extensions (在 System.Web.Extensions.dll 中)
<ToolboxBitmapAttribute(GetType(DataPager), "DataPager.ico")> _
<ThemeableAttribute(True)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class DataPager _
Inherits Control _
Implements IAttributeAccessor, INamingContainer, ICompositeControlDesignerAccessor
Dim instance As DataPager
[ToolboxBitmapAttribute(typeof(DataPager), "DataPager.ico")]
[ThemeableAttribute(true)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class DataPager : Control, IAttributeAccessor,
INamingContainer, ICompositeControlDesignerAccessor
[ToolboxBitmapAttribute(typeof(DataPager), L"DataPager.ico")]
[ThemeableAttribute(true)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class DataPager : public Control,
IAttributeAccessor, INamingContainer, ICompositeControlDesignerAccessor
/** @attribute ToolboxBitmapAttribute(DataPager, "DataPager.ico") */
/** @attribute ThemeableAttribute(true) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public class DataPager extends Control implements IAttributeAccessor,
INamingContainer, ICompositeControlDesignerAccessor
public class DataPager extends Control implements IAttributeAccessor, INamingContainer, ICompositeControlDesignerAccessor
DataPager 類別 (Class) 可用來將資料進行分頁,以及針對實作 IPageableItemContainer 介面的資料繫結控制項顯示巡覽控制項 (實作這個介面的控制項範例是 ListView 控制項)。
您可以使用 PagedControlID 屬性 (Property),使 DataPager 控制項與資料繫結控制項產生關聯。或者,也可以將 DataPager 控制項放在資料繫結控制階層架構內。例如,在 ListView 控制項中,可以將 DataPager 控制項放在 ListView..::.LayoutTemplate 範本內。
您可以藉由變更 PageSize 屬性 (Property),自訂每個資料頁上顯示的項目數。同時也可以設定 QueryStringField 屬性 (Property),變更將頁面送出至伺服器的方式。
頁面巡覽區欄位
為了讓 DataPager 控制項顯示巡覽控制項,您必須先將頁面巡覽區欄位加入至該控制項。頁面巡覽區欄位衍生自 DataPagerField 類別。下表列出可用的頁面巡覽區欄位型別。
若要以宣告方式將頁面巡覽區欄位加入至 DataPager 控制項,請將 Fields 項目加入至 DataPager 控制項。然後,您可以將頁面巡覽區欄位加入至 Fields 項目中。頁面巡覽區欄位會依它們出現在 Fields 項目中的順序加入至 Fields 集合。Fields 集合可讓您以程式設計方式管理 DataPager 控制項中的頁面巡覽區欄位。
頁面屬性
網頁可及性
預設針對這個控制項呈現的標記,可能未符合網頁可及性標準 (如無障礙網頁開發規範 1.0 (WCAG) 優先權 1 方針)。如需這個控制項之網頁可及性支援的詳細資訊,請參閱 ASP.NET 控制項和網頁可及性。
下列範例顯示如何將分頁功能加入至 ListView 控制項。這個範例包含兩個 DataPager 控制項,這兩個控制項是用來逐頁巡覽同一個 ListView 控制項的資料。
<%@ Page language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head id="Head1" runat="server">
<title>DataPager Example</title>
<style type="text/css">
th
{
background-color:#eef4fa;
border-top:solid 1px #9dbbcc;
border-bottom:solid 1px #9dbbcc;
}
.itemSeparator { border-right: 1px solid #ccc }
.groupSeparator
{
height: 1px;
background-color: #cccccc;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<h3>DataPager Example</h3>
<!-- The first DataPager control. -->
<asp:DataPager runat="server" ID="BeforeListDataPager"
PagedControlID="ProductsListView"
PageSize="18">
<Fields>
<asp:NextPreviousPagerField ButtonType="Image"
ShowFirstPageButton="true"
ShowNextPageButton="false"
ShowPreviousPageButton="false"
FirstPageImageUrl="~/images/first.gif" />
<asp:NumericPagerField ButtonCount="10" />
<asp:NextPreviousPagerField ButtonType="Image"
ShowLastPageButton="true"
ShowNextPageButton="false"
ShowPreviousPageButton="false"
LastPageImageUrl="~/images/last.gif" />
</Fields>
</asp:DataPager>
<asp:ListView ID="ProductsListView"
DataSourceID="ProductsDataSource"
GroupItemCount="3"
runat="server">
<LayoutTemplate>
<table cellpadding="2" width="640px" id="tbl1" runat="server">
<tr>
<th colspan="5">PRODUCTS LIST</th>
</tr>
<tr runat="server" id="groupPlaceholder"></tr>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr runat="server" id="tr1">
<td runat="server" id="itemPlaceholder"></td>
</tr>
</GroupTemplate>
<GroupSeparatorTemplate>
<tr runat="server">
<td colspan="5">
<div class="groupSeparator"><hr></div>
</td>
</tr>
</GroupSeparatorTemplate>
<ItemTemplate>
<td align="center" runat="server">
<asp:HyperLink ID="ProductLink" runat="server"
Text='<%# Eval("Name") %>'
NavigateUrl='<%# "ProductDetails.aspx?productID=" & Eval("ProductID") %>' /><br />
<asp:Image ID="ProductImage" runat="server"
ImageUrl='<%#"~/images/thumbnails/" & Eval("ThumbnailPhotoFileName") %>' /><br />
<b>Price:</b> <%# Eval("ListPrice", "{0:c}")%> <br />
</td>
</ItemTemplate>
<ItemSeparatorTemplate>
<td class="itemSeparator" runat="server"> </td>
</ItemSeparatorTemplate>
</asp:ListView>
<!-- The second DataPager control. -->
<asp:DataPager runat="server" ID="AfterListDataPager"
PagedControlID="ProductsListView"
PageSize="18">
<Fields>
<asp:NextPreviousPagerField ButtonType="Image"
ShowFirstPageButton="true"
ShowNextPageButton="false"
ShowPreviousPageButton="false"
FirstPageImageUrl="~/images/first.gif" />
<asp:NumericPagerField ButtonCount="10" />
<asp:NextPreviousPagerField ButtonType="Image"
ShowLastPageButton="true"
ShowNextPageButton="false"
ShowPreviousPageButton="false"
LastPageImageUrl="~/images/last.gif" />
</Fields>
</asp:DataPager>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the AdventureWorks sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:SqlDataSource ID="ProductsDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
SelectCommand="SELECT P.ProductID, P.Name, P.Color, P.ListPrice,
PF.ThumbnailPhotoFileName
FROM Production.Product AS P
INNER JOIN Production.ProductProductPhoto AS PPF ON P.ProductID = PPF.ProductID
INNER JOIN Production.ProductPhoto AS PF ON PPF.ProductPhotoID = PF.ProductPhotoID">
</asp:SqlDataSource>
</form>
</body>
</html>
<%@ Page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head id="Head1" runat="server">
<title>DataPager Example</title>
<style type="text/css">
th
{
background-color:#eef4fa;
border-top:solid 1px #9dbbcc;
border-bottom:solid 1px #9dbbcc;
}
.itemSeparator { border-right: 1px solid #ccc }
.groupSeparator
{
height: 1px;
background-color: #cccccc;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<h3>DataPager Example</h3>
<!-- The first DataPager control. -->
<asp:DataPager runat="server" ID="BeforeListDataPager"
PagedControlID="ProductsListView"
PageSize="18">
<Fields>
<asp:NextPreviousPagerField ButtonType="Image"
ShowFirstPageButton="true"
ShowNextPageButton="false"
ShowPreviousPageButton="false"
FirstPageImageUrl="~/images/first.gif" />
<asp:NumericPagerField ButtonCount="10" />
<asp:NextPreviousPagerField ButtonType="Image"
ShowLastPageButton="true"
ShowNextPageButton="false"
ShowPreviousPageButton="false"
LastPageImageUrl="~/images/last.gif" />
</Fields>
</asp:DataPager>
<asp:ListView ID="ProductsListView"
DataSourceID="ProductsDataSource"
GroupItemCount="3"
runat="server">
<LayoutTemplate>
<table cellpadding="2" width="640px" id="tbl1" runat="server">
<tr>
<th colspan="5">PRODUCTS LIST</th>
</tr>
<tr runat="server" id="groupPlaceholder"></tr>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr runat="server" id="tr1">
<td runat="server" id="itemPlaceholder"></td>
</tr>
</GroupTemplate>
<GroupSeparatorTemplate>
<tr runat="server">
<td colspan="5">
<div class="groupSeparator"><hr></div>
</td>
</tr>
</GroupSeparatorTemplate>
<ItemTemplate>
<td align="center" runat="server">
<asp:HyperLink ID="ProductLink" runat="server"
Text='<%# Eval("Name") %>'
NavigateUrl='<%# "ProductDetails.aspx?productID=" + Eval("ProductID") %>' /><br />
<asp:Image ID="ProductImage" runat="server"
ImageUrl='<%#"~/images/thumbnails/" + Eval("ThumbnailPhotoFileName") %>' /><br />
<b>Price:</b> <%# Eval("ListPrice", "{0:c}")%> <br />
</td>
</ItemTemplate>
<ItemSeparatorTemplate>
<td class="itemSeparator" runat="server"> </td>
</ItemSeparatorTemplate>
</asp:ListView>
<!-- The second DataPager control. -->
<asp:DataPager runat="server" ID="AfterListDataPager"
PagedControlID="ProductsListView"
PageSize="18">
<Fields>
<asp:NextPreviousPagerField ButtonType="Image"
ShowFirstPageButton="true"
ShowNextPageButton="false"
ShowPreviousPageButton="false"
FirstPageImageUrl="~/images/first.gif" />
<asp:NumericPagerField ButtonCount="10" />
<asp:NextPreviousPagerField ButtonType="Image"
ShowLastPageButton="true"
ShowNextPageButton="false"
ShowPreviousPageButton="false"
LastPageImageUrl="~/images/last.gif" />
</Fields>
</asp:DataPager>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the AdventureWorks sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:SqlDataSource ID="ProductsDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
SelectCommand="SELECT P.ProductID, P.Name, P.Color, P.ListPrice,
PF.ThumbnailPhotoFileName
FROM Production.Product AS P
INNER JOIN Production.ProductProductPhoto AS PPF ON P.ProductID = PPF.ProductID
INNER JOIN Production.ProductPhoto AS PF ON PPF.ProductPhotoID = PF.ProductPhotoID">
</asp:SqlDataSource>
</form>
</body>
</html>
System..::.Object
System.Web.UI..::.Control
System.Web.UI.WebControls..::.DataPager
這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。
Windows Vista, Windows XP SP2, Windows Server 2003
.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求。
.NET Framework
支援版本:3.5
參考
其他資源