DataPagerField 类

定义

用作数据页导航字段类型的基类,这些类型表示 DataPager 控件的导航控件。

public ref class DataPagerField abstract : System::Web::UI::IStateManager
public abstract class DataPagerField : System.Web.UI.IStateManager
type DataPagerField = class
    interface IStateManager
Public MustInherit Class DataPagerField
Implements IStateManager
继承
DataPagerField
派生
实现

示例

以下示例演示如何使用 NextPreviousPagerFieldNumericPagerFieldTemplatePagerField 对象在控件中 DataPager 显示页面导航控件。 对象派生自 DataPagerField 类。

<%@ 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>DataPagerField Example</title>    
    <style type="text/css">
      body  
      {
        text-align: center; 
        font: 13px Tahoma, Arial, Helvetica;
      }
      .item
      {
        border-bottom: solid 1px #FFA500;
        font-weight:bold;
      }
    </style>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>DataPagerField Example</h3>
          
      <asp:ListView ID="ProductsListView" 
        DataSourceID="ContactsDataSource"
        runat="server">
        <LayoutTemplate>
          <table runat="server" id="tblProducts" width="350">
            <tr runat="server" id="itemPlaceholder" />
          </table>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td class="item">
              <asp:Label ID="NameLabel" runat="server" 
                Text='<%#Eval("Name") %>' />
            </td>
          </tr>
          <tr runat="server">
            <td>
              <asp:Label ID="DescriptionLabel" runat="server" 
                Text='<%#Eval("Description")%>' />
            </td>
          </tr>
        </ItemTemplate>
        <ItemSeparatorTemplate>
          <tr runat="server">
            <td> </td>
          </tr>
        </ItemSeparatorTemplate>
      </asp:ListView>
      <br />

      <asp:DataPager runat="server" 
        ID="ProductsDataPager" 
        PageSize="5"
        PagedControlID="ProductsListView">
        <Fields>
          <asp:TemplatePagerField>
            <PagerTemplate>
            <b>
            Page
            <asp:Label runat="server" ID="CurrentPageLabel" 
              Text="<%# Container.TotalRowCount>0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0 %>" />
            of
            <asp:Label runat="server" ID="TotalPagesLabel" 
              Text="<%# Math.Ceiling ((double)Container.TotalRowCount / Container.PageSize) %>" />
            </b>
            <br /><br />
            </PagerTemplate>
          </asp:TemplatePagerField>
          
          <asp:NextPreviousPagerField
            ShowFirstPageButton="true"
            ShowNextPageButton="false"
            ShowPreviousPageButton="false" />
          
          <asp:NumericPagerField 
            PreviousPageText="<<"
            NextPageText=">>"
            ButtonCount="10" />
            
          <asp:NextPreviousPagerField
            ShowLastPageButton="true"
            ShowNextPageButton="false"
            ShowPreviousPageButton="false" />
        </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="ContactsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT P.Name, PD.Description 
                      FROM Production.ProductModel AS PM 
                      INNER JOIN Production.Product AS P ON PM.ProductModelID = P.ProductModelID 
                      INNER JOIN Production.ProductModelProductDescriptionCulture AS PMPDC 
                      ON PM.ProductModelID = PMPDC.ProductModelID 
                      INNER JOIN Production.ProductDescription AS PD 
                      ON PMPDC.ProductDescriptionID = PD.ProductDescriptionID 
                      WHERE (PMPDC.CultureID = 'en')">
      </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>DataPagerField Example</title>    
    <style type="text/css">
      body  
      {
        text-align: center; 
        font: 13px Tahoma, Arial, Helvetica;
      }
      .item
      {
        border-bottom: solid 1px #FFA500;
        font-weight:bold;
      }
    </style>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>DataPagerField Example</h3>
          
      <asp:ListView ID="ProductsListView" 
        DataSourceID="ContactsDataSource"
        runat="server">
        <LayoutTemplate>
          <table runat="server" id="tblProducts" width="350">
            <tr runat="server" id="itemPlaceholder" />
          </table>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td class="item">
              <asp:Label ID="NameLabel" runat="server" 
                Text='<%#Eval("Name") %>' />
            </td>
          </tr>
          <tr runat="server">
            <td>
              <asp:Label ID="DescriptionLabel" runat="server" 
                Text='<%#Eval("Description")%>' />
            </td>
          </tr>
        </ItemTemplate>
        <ItemSeparatorTemplate>
          <tr runat="server">
            <td> </td>
          </tr>
        </ItemSeparatorTemplate>
      </asp:ListView>
      <br />

      <asp:DataPager runat="server" 
        ID="ProductsDataPager" 
        PageSize="5"
        PagedControlID="ProductsListView">
        <Fields>
          <asp:TemplatePagerField>
            <PagerTemplate>
            <b>
            Page
            <asp:Label runat="server" ID="CurrentPageLabel" 
              Text="<%# IIf(Container.TotalRowCount>0, (Container.StartRowIndex / Container.PageSize) + 1, 0) %>" />
            of
            <asp:Label runat="server" ID="TotalPagesLabel" 
              Text="<%# Math.Ceiling (System.Convert.ToDouble(Container.TotalRowCount) / Container.PageSize) %>" />
            </b>
            <br /><br />            
            </PagerTemplate>
          </asp:TemplatePagerField>
          
          <asp:NextPreviousPagerField
            ShowFirstPageButton="true"
            ShowNextPageButton="false"
            ShowPreviousPageButton="false" />
          
          <asp:NumericPagerField 
            PreviousPageText="<<"
            NextPageText=">>"
            ButtonCount="10" />
            
          <asp:NextPreviousPagerField
            ShowLastPageButton="true"
            ShowNextPageButton="false"
            ShowPreviousPageButton="false" />
        </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="ContactsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT P.Name, PD.Description 
                      FROM Production.ProductModel AS PM 
                      INNER JOIN Production.Product AS P ON PM.ProductModelID = P.ProductModelID 
                      INNER JOIN Production.ProductModelProductDescriptionCulture AS PMPDC 
                      ON PM.ProductModelID = PMPDC.ProductModelID 
                      INNER JOIN Production.ProductDescription AS PD 
                      ON PMPDC.ProductDescriptionID = PD.ProductDescriptionID 
                      WHERE (PMPDC.CultureID = 'en')">
      </asp:SqlDataSource>
      
    </form>
  </body>
</html>

注解

DataPagerField 充当所有数据寻呼字段类型的基类。 控件使用 DataPager 数据页字段来表示导航控件。

使用派生自 DataPagerField 的类选择控件中显示的 DataPager 寻呼类型。 下表列出了可用的数据寻呼字段类型。

Pager 字段类型 说明
NextPreviousPagerField 允许用户一次浏览一页的数据页,或跳转到第一页或最后一页。
NumericPagerField 允许用户按页码选择页面。
TemplatePagerField 允许页面开发人员创建自定义分页 UI。

可以从 类派生 DataPagerField ,以创建其他寻呼字段类型。

实施者说明

DataPagerField 类继承时,必须重写以下成员:

构造函数

DataPagerField()

初始化 DataPagerField 类的新实例。

属性

DataPager

获取对数据页导航的引用,该数据页导航与 DataPagerField 对象关联。

IsTrackingViewState

获取一个值,该值指示 DataPagerField 对象是否在跟踪其视图状态更改。

QueryStringHandled

获取或设置一个值,该值指示是否已对查询字符串字段进行计算。

QueryStringValue

从请求的 URL 获取查询字符串字段的值。

ViewState

获取状态信息的字典,这些信息使您可以在同一页的多个请求间保存和还原 DataPagerField 对象的视图状态。

Visible

获取或设置指示是否呈现数据页导航字段的值。

方法

CloneField()

创建从 DataPagerField 派生的当前对象的副本。

CopyProperties(DataPagerField)

将从 DataPagerField 派生的当前对象的属性复制到指定的 DataPagerField 对象。

CreateDataPagers(DataPagerFieldItem, Int32, Int32, Int32, Int32)

在派生类中重写时,为数据页导航字段对象创建用户界面 (UI) 控件并将它们添加到指定的容器。

CreateField()

在派生类中重写时,创建从 DataPagerField 派生的空对象。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetQueryStringNavigateUrl(Int32)

创建一个 URL,该 URL 包含具有指定页码的查询字符串字段。

GetType()

获取当前实例的 Type

(继承自 Object)
HandleEvent(CommandEventArgs)

在派生类中重写时,处理在数据页导航字段对象中发生的事件。

LoadViewState(Object)

还原以前保存的视图状态信息。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
OnFieldChanged()

引发 FieldChanged 事件。

SaveViewState()

保存对 DataPagerField 对象的视图状态所做的更改。

ToString()

返回表示当前对象的字符串。

(继承自 Object)
TrackViewState()

使 DataPagerField 对象跟踪其视图状态更改,以便这些更改可以存储在控件的 ViewState 属性中并在同一页的不同请求间保留。

显式接口实现

IStateManager.IsTrackingViewState

获取一个值,该值指示 DataPagerField 对象是否在跟踪其视图状态更改。

IStateManager.LoadViewState(Object)

还原以前保存的视图状态信息。

IStateManager.SaveViewState()

保存对 DataPagerField 对象的视图状态所做的更改。

IStateManager.TrackViewState()

使 DataPagerField 对象跟踪其视图状态更改,以便这些更改可以存储在控件的 ViewState 属性中并在同一页的不同请求间保留。

适用于

另请参阅