DataPager 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供實作 IPageableItemContainer 介面的資料繫結控制項分頁功能,例如 ListView 控制項。
public ref class DataPager : System::Web::UI::Control, System::Web::UI::IAttributeAccessor, System::Web::UI::INamingContainer, System::Web::UI::WebControls::ICompositeControlDesignerAccessor
[System.Drawing.ToolboxBitmap(typeof(System.Web.UI.WebControls.DataPager), "DataPager.ico")]
[System.Web.UI.Themeable(true)]
public class DataPager : System.Web.UI.Control, System.Web.UI.IAttributeAccessor, System.Web.UI.INamingContainer, System.Web.UI.WebControls.ICompositeControlDesignerAccessor
[System.Web.UI.Themeable(true)]
[System.Drawing.ToolboxBitmap(typeof(System.Web.UI.WebControls.DataPager), "DataPager.bmp")]
public class DataPager : System.Web.UI.Control, System.Web.UI.IAttributeAccessor, System.Web.UI.INamingContainer, System.Web.UI.WebControls.ICompositeControlDesignerAccessor
[<System.Drawing.ToolboxBitmap(typeof(System.Web.UI.WebControls.DataPager), "DataPager.ico")>]
[<System.Web.UI.Themeable(true)>]
type DataPager = class
inherit Control
interface IAttributeAccessor
interface INamingContainer
interface ICompositeControlDesignerAccessor
[<System.Web.UI.Themeable(true)>]
[<System.Drawing.ToolboxBitmap(typeof(System.Web.UI.WebControls.DataPager), "DataPager.bmp")>]
type DataPager = class
inherit Control
interface IAttributeAccessor
interface INamingContainer
interface ICompositeControlDesignerAccessor
Public Class DataPager
Inherits Control
Implements IAttributeAccessor, ICompositeControlDesignerAccessor, INamingContainer
- 繼承
- 屬性
- 實作
範例
下列範例示範如何將分頁功能新增至 ListView 控制項。 此範例包含兩 DataPager 個控制項,用來逐頁流覽相同 ListView 控制項的資料。
<%@ Page language="C#" %>
<!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" >
<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="VB" %>
<!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" >
<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>
備註
本主題內容:
簡介
類別 DataPager 是用來分頁資料,以及顯示實作 介面之資料繫結控制項的 IPageableItemContainer 導覽控制項。 (實作 介面的控制項範例是 ListView control.)
您可以使用 屬性,將控制項與資料繫結控制項 PagedControlID 產生關聯 DataPager 。 或者,您可以將控制項放在 DataPager 資料繫結控制項階層中。 例如,在 控制項中 ListView ,您可以將控制項放在 DataPager 範本內 ListView.LayoutTemplate 。
您可以藉由變更 PageSize 屬性,自訂針對每個資料頁面顯示的專案數。 您也可以藉由設定 QueryStringField 屬性來變更頁面提交至伺服器的方式。
呼叫器欄位
若要讓 DataPager 控制項顯示導覽控制項,您必須將呼叫器欄位新增至控制項。 呼叫器欄位衍生自 DataPagerField 類別。 下表列出您可以使用的呼叫器欄位類型。
呼叫器欄位類型 | 描述 |
---|---|
NextPreviousPagerField | 讓使用者一次流覽一頁,或跳到第一頁或最後一頁。 |
NumericPagerField | 可讓使用者依頁碼選取頁面。 |
TemplatePagerField | 可讓您建立自訂分頁 UI。 |
若要以宣告方式將呼叫器欄位新增至 DataPager 控制項,請將 專案 DataPager 加入 Fields
控制項。 然後,您可以將呼叫器欄位新增至 Fields
元素。 呼叫器欄位會依元素中 Fields
出現的順序新增至 Fields 集合。 集合 Fields 可讓您以程式設計方式管理 控制項中的 DataPager 呼叫器欄位。
頁面屬性
下表列出指定資料頁面特性之 DataPager 控制項的唯讀屬性。 這些屬性通常用於 物件中的 TemplatePagerField 系結運算式。
屬性 | 描述 |
---|---|
MaximumRows | 每個資料頁上顯示的最大資料錄筆數。 |
StartRowIndex | 顯示在資料頁上第一筆資料錄的索引。 |
TotalRowCount | 基礎資料來源中可用的記錄總數。 |
Accessibility
此控制項預設轉譯的預設標記可能不符合協助工具標準,例如 Web 內容協助工具指導方針 1.0 (WCAG) 優先順序 1 指導方針。 如需此控制項協助工具支援的詳細資訊,請參閱 ASP.NET 控制項和協助工具。
宣告式語法
<asp:DataPager
EnableTheming="True|False"
EnableViewState="True|False"
ID="string"
OnDataBinding="DataBinding event handler"
OnDisposed="Disposed event handler"
OnInit="Init event handler"
OnLoad="Load event handler"
OnPreRender="PreRender event handler"
OnUnload="Unload event handler"
PagedControlID="string"
PageSize="integer"
runat="server"
SkinID="string"
Visible="True|False"
>
<Fields>
<asp:NextPreviousPagerField
ButtonCssClass="string"
ButtonType="Button|Image|Link"
FirstPageImageUrl="string"
FirstPageText="string"
LastPageImageUrl="string"
LastPageText="string"
NextPageImageUrl="string"
NextPageText="string"
PreviousPageImageUrl="string"
PreviousPageText="string"
RenderDisabledButtonsAsLabels="True|False"
RenderNonBreakingSpacesBetweenControls="True|False"
ShowFirstPageButton="True|False"
ShowLastPageButton="True|False"
ShowNextPageButton="True|False"
ShowPreviousPageButton="True|False"
Visible="True|False"
/>
<asp:NumericPagerField
ButtonCount="integer"
ButtonType="Button|Image|Link"
CurrentPageLabelCssClass="string"
NextPageImageUrl="string"
NextPageText="string"
NextPreviousButtonCssClass="string"
NumericButtonCssClass="string" PreviousPageImageUrl="string"
PreviousPageText="string"
RenderNonBreakingSpacesBetweenControls="True|False"
Visible="True|False"
/>
<asp:TemplatePagerField
OnPagerCommand="PagerCommand event handler"
Visible="True|False"
/>
</Fields>
</asp:DataPager>
建構函式
DataPager() |
初始化 DataPager 類別的新執行個體。 |
屬性
Adapter |
針對控制項取得瀏覽器的特定配置器。 (繼承來源 Control) |
AppRelativeTemplateSourceDirectory |
取得或設定包含了此控制項之 Page 或 UserControl 物件的相對應用程式虛擬目錄。 (繼承來源 Control) |
Attributes |
取得 DataPager 控制項的自訂屬性名稱/值組集合。 |
BindingContainer |
取得包含了此控制項之資料繫結的控制項。 (繼承來源 Control) |
ChildControlsCreated |
取得值,指出是否已經建立伺服器控制項的子控制項。 (繼承來源 Control) |
ClientID |
取得 ASP.NET 所產生之 HTML 標記的控制項識別碼。 (繼承來源 Control) |
ClientIDMode |
取得或設定用來產生 ClientID 屬性值的演算法。 (繼承來源 Control) |
ClientIDSeparator |
取得字元值,表示在 ClientID 屬性中所使用的分隔字元。 (繼承來源 Control) |
Context |
取得與目前 Web 要求的伺服器控制項關聯的 HttpContext 物件。 (繼承來源 Control) |
Controls |
取得 ControlCollection 物件,這個物件表示 UI 階層架構中 DataPager 控制項的子控制項。 |
DataItemContainer |
如果命名容器實作 IDataItemContainer,則取得命名容器的參考。 (繼承來源 Control) |
DataKeysContainer |
如果命名容器實作 IDataKeysControl,則取得命名容器的參考。 (繼承來源 Control) |
DesignMode |
取得值,指出控制項是否正用於設計介面上。 (繼承來源 Control) |
EnableTheming |
取得或設定值,指出佈景主題是否套用至此控制項。 (繼承來源 Control) |
EnableViewState |
取得或設定值,該值表示伺服器控制項是否對要求的用戶端而言保持其檢視狀態,以及它包含的任何子控制項狀態。 (繼承來源 Control) |
Events |
取得控制項事件處理常式委派 (Delegate) 的清單。 這個屬性是唯讀的。 (繼承來源 Control) |
Fields |
取得 DataPagerField 物件的集合,這些物件表示 DataPager 控制項中指定的頁面巡覽區欄位。 |
HasChildViewState |
取得值,指出目前伺服器控制項的子控制項是否有任何已儲存的檢視狀態設定。 (繼承來源 Control) |
ID |
取得或設定指派給伺服器控制項的程式設計識別項。 (繼承來源 Control) |
IdSeparator |
取得用來分隔控制項識別項的字元。 (繼承來源 Control) |
IsChildControlStateCleared |
取得值,指出這個控制項中所包含的控制項是否有控制項狀態。 (繼承來源 Control) |
IsTrackingViewState |
取得值,指出伺服器控制項是否正在儲存檢視狀態的變更。 (繼承來源 Control) |
IsViewStateEnabled |
取得值,指出這個控制項是否已啟用檢視狀態。 (繼承來源 Control) |
LoadViewStateByID |
取得值,指出控制項是否依 ID (而不是索引) 參與載入其檢視狀態。 (繼承來源 Control) |
MaximumRows |
取得每個資料頁上顯示的最大資料錄筆數。 |
NamingContainer |
取得伺服器控制項命名容器的參考,其建立唯一命名空間,在具有相同 ID 屬性值的伺服器控制項之間作區別。 (繼承來源 Control) |
Page |
取得含有伺服器控制項的 Page 執行個體的參考。 (繼承來源 Control) |
PagedControlID | |
PageSize |
取得或設定每個資料頁上顯示的資料錄筆數。 |
Parent |
在網頁控制階層架構中取得伺服器控制項之父控制項的參考。 (繼承來源 Control) |
QueryStringField |
取得或設定查詢字串欄位的名稱。 |
RenderingCompatibility |
取得值,這個值會指定將與呈現 HTML 相容的 ASP.NET 版本。 (繼承來源 Control) |
Site |
當呈現在設計介面上時,取得裝載目前控制項之容器的資訊。 (繼承來源 Control) |
SkinID |
取得或設定要套用至控制項的面板。 (繼承來源 Control) |
StartRowIndex |
取得資料頁上顯示的第一筆記錄的索引。 |
TagKey |
取得用於呈現 DataPager 控制項的 HTML 項目。 |
TemplateControl |
取得或設定包含了此控制項之樣板的參考。 (繼承來源 Control) |
TemplateSourceDirectory |
取得包含目前伺服器控制項的 Page 或 UserControl 的虛擬目錄。 (繼承來源 Control) |
TotalRowCount |
取得由相關資料繫結控制項參考之基礎資料來源物件所擷取的資料錄總數。 |
UniqueID |
取得伺服器控制項唯一的、符合階層架構的識別項。 (繼承來源 Control) |
ValidateRequestMode |
取得或設定值,指出控制項是否對來自瀏覽器的用戶端輸入檢查潛在的危險值。 (繼承來源 Control) |
ViewState |
取得狀態資訊的字典,允許您在相同網頁的多個要求之間,儲存和還原伺服器控制項的檢視狀態。 (繼承來源 Control) |
ViewStateIgnoresCase |
取得值,指出 StateBag 物件是否不區分大小寫。 (繼承來源 Control) |
ViewStateMode |
取得或設定這個控制項的檢視狀態模式。 (繼承來源 Control) |
Visible |
取得或設定值,指出伺服器控制項是否會轉譯為頁面上的 UI。 (繼承來源 Control) |
方法
事件
DataBinding |
發生於伺服器控制項繫結至資料來源時。 (繼承來源 Control) |
Disposed |
發生於伺服器控制項從記憶體釋放時,這是在要求 ASP.NET 網頁時,伺服器控制項生命週期的最後階段。 (繼承來源 Control) |
Init |
發生於初始化伺服器控制項時,是其生命週期中的第一個步驟。 (繼承來源 Control) |
Load |
發生於載入伺服器控制項至 Page 物件時。 (繼承來源 Control) |
PreRender |
在 Control 物件載入之後但在呈現之前發生。 (繼承來源 Control) |
Unload |
發生於伺服器控制項從記憶體卸載時。 (繼承來源 Control) |
明確介面實作
擴充方法
FindDataSourceControl(Control) |
傳回與指定之控制項的資料控制項相關聯的資料來源。 |
FindFieldTemplate(Control, String) |
傳回在指定之控制項的命名容器中所指定資料行的欄位樣板。 |
FindMetaTable(Control) |
傳回包含資料控制項的中繼資料表物件。 |
GetDefaultValues(INamingContainer) |
取得所指定資料控制項的預設值集合。 |
GetMetaTable(INamingContainer) |
取得所指定資料控制項中的資料表中繼資料。 |
SetMetaTable(INamingContainer, MetaTable) |
設定所指定資料控制項中的資料表中繼資料。 |
SetMetaTable(INamingContainer, MetaTable, IDictionary<String,Object>) |
設定所指定資料控制項的資料表中繼資料及預設值對應。 |
SetMetaTable(INamingContainer, MetaTable, Object) |
設定所指定資料控制項的資料表中繼資料及預設值對應。 |
TryGetMetaTable(INamingContainer, MetaTable) |
判斷資料表中繼資料是否可供使用。 |
EnableDynamicData(INamingContainer, Type) |
針對指定的資料控制項啟用動態資料行為。 |
EnableDynamicData(INamingContainer, Type, IDictionary<String,Object>) |
針對指定的資料控制項啟用動態資料行為。 |
EnableDynamicData(INamingContainer, Type, Object) |
針對指定的資料控制項啟用動態資料行為。 |
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應