NumericPagerField 類別

定義

代表 DataPager 欄位,可讓使用者依照頁碼選取頁面。Represents a DataPager field that enables users to select a page by page number.

public ref class NumericPagerField : System::Web::UI::WebControls::DataPagerField
public class NumericPagerField : System.Web.UI.WebControls.DataPagerField
type NumericPagerField = class
    inherit DataPagerField
Public Class NumericPagerField
Inherits DataPagerField
繼承
NumericPagerField

範例

下列範例顯示如何使用NumericPagerField物件來逐頁查看ListView控制項中顯示的資料。The following example shows how to use a NumericPagerField object to page through data that is displayed in a ListView control.

<%@ 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>NumericPagerField Example</title>    
    <style type="text/css">
      body 	
      {
        text-align: center;
        font: 12px Arial, Helvetica, sans-serif;
      } 
      table
      {
        padding: 2px 2px 2px 2px;
        border: 1px solid;
        width: 500px;
      }     
      .CurrentPage 
      {
        padding: 2px 6px;
        border: solid 1px #ddd; 
        background: #2E8B57;
        color:White;
      }
      .PrevNext,.PageNumber
      {
        padding: 2px 6px;
        border: solid 1px #ddd;
        text-decoration: none;
        color: #2E8B57;
      }
      .PageNumber:hover, .PrevNext:hover
      {
        background-color: #FFA500;
        color: White;
      }
    </style>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>NumericPagerField Example</h3>
          
      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource"
        runat="server">
        <LayoutTemplate>
          <table runat="server" id="tblContacts">
            <tr id="itemPlaceholder" runat="server">
            </tr>
          </table>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td>
              <asp:Label ID="IDLabel" runat="server" Text='<%#Eval("ContactID") %>' />
            </td>
            <td align="left">
              <asp:Label ID="NameLabel" runat="server" 
                Text='<%#Eval("LastName") + ", " + Eval("FirstName")%>' />
            </td>
          </tr>
        </ItemTemplate>
      </asp:ListView>
      <br />

      <div>
        <asp:DataPager runat="server" 
          ID="ContactsDataPager" 
          PagedControlID="ContactsListView">
          <Fields>
            <asp:NumericPagerField 
              PreviousPageText="&lt; Prev"
              NextPageText="Next &gt;"
              ButtonCount="10"
              NextPreviousButtonCssClass="PrevNext"
              CurrentPageLabelCssClass="CurrentPage"
              NumericButtonCssClass="PageNumber" />
          </Fields>
        </asp:DataPager>
      </div>
      <br />

      <!-- 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 [ContactID], [FirstName], [LastName] 
          FROM Person.Contact">
      </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>NumericPagerField Example</title>    
    <style type="text/css">
      body 	
      {
        text-align: center;
        font: 12px Arial, Helvetica, sans-serif;
      } 
      table
      {
        padding: 2px 2px 2px 2px;
        border: 1px solid;
        width: 500px;
      }     
      .CurrentPage 
      {
        padding: 2px 6px;
        border: solid 1px #ddd; 
        background: #2E8B57;
        color:White;
      }
      .PrevNext,.PageNumber
      {
        padding: 2px 6px;
        border: solid 1px #ddd;
        text-decoration: none;
        color: #2E8B57;
      }
      .PageNumber:hover, .PrevNext:hover
      {
        background-color: #FFA500;
        color: White;
      }
    </style>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>NumericPagerField Example</h3>
          
      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource"
        runat="server">
        <LayoutTemplate>
          <table runat="server" id="tblContacts">
            <tr id="itemPlaceholder" runat="server">
            </tr>
          </table>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td>
              <asp:Label ID="IDLabel" runat="server" Text='<%#Eval("ContactID") %>' />
            </td>
            <td align="left">
              <asp:Label ID="NameLabel" runat="server" 
                Text='<%#Eval("LastName") & ", " & Eval("FirstName")%>' />
            </td>
          </tr>
        </ItemTemplate>
      </asp:ListView>
      <br />

      <div>
        <asp:DataPager runat="server" 
          ID="ContactsDataPager" 
          PagedControlID="ContactsListView">
          <Fields>
            <asp:NumericPagerField 
              PreviousPageText="&lt; Prev"
              NextPageText="Next &gt;"
              ButtonCount="10"
              NextPreviousButtonCssClass="PrevNext"
              CurrentPageLabelCssClass="CurrentPage"
              NumericButtonCssClass="PageNumber" />
          </Fields>
        </asp:DataPager>
      </div>
      <br />

      <!-- 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 [ContactID], [FirstName], [LastName] 
          FROM Person.Contact">
      </asp:SqlDataSource>
      
    </form>
  </body>
</html>

備註

類別會顯示DataPager控制項中的導覽控制項。 NumericPagerFieldThe NumericPagerField class displays navigation controls in a DataPager control. 控制項可以用來逐頁查看執行IPageableItemContainer介面之控制項 (例如ListView控制項) 所顯示的資料。The controls can be used to page through data that is displayed by a control that implements the IPageableItemContainer interface, such as the ListView control. 物件NumericPagerField會將頁碼顯示為按鈕, 讓使用者可以按一下以移至特定頁面。The NumericPagerField object displays page numbers as buttons that users can click to move to specific a page. 控制項也會顯示下一頁和上一頁按鈕, 讓使用者可以存取比控制項所顯示的資料更多的頁面。The control also displays next-page and previous-page buttons that enable users to access more pages of data than the ones that are displayed by the control.

您可以使用下表所列NumericPagerField的屬性來自訂物件的外觀。You can customize the appearance of the NumericPagerField object by using the properties that are listed in the following table.

屬性Property 說明Description
CurrentPageLabelCssClass 目前頁碼的 CSS 類別。The CSS class for the current page number.
NextPreviousButtonCssClass 下一頁頁面和上一頁按鈕的 CSS 類別。The CSS class for the next-page and previous-page buttons.
NumericButtonCssClass 代表頁碼之按鈕的 CSS 類別。The CSS class for the buttons that represent the page numbers.

您可以使用ButtonType屬性來選取將顯示的按鈕類型。You can use the ButtonType property to select the type of button that will be displayed. 下表列出可用的按鈕類型。The following table lists the available button types.

按鈕類型Button type 說明Description
ButtonType.Button Button 控制項。A Button control.
ButtonType.Image ImageButton 控制項。An ImageButton control.
ButtonType.Link LinkButton 控制項。A LinkButton control.

NumericButtonCssClass物件內的控制項會以不間斷的空間呈現。The controls inside the NumericButtonCssClass object are rendered with non-breaking spaces between them. 如果您想要自訂此行為, 可以使用RenderNonBreakingSpacesBetweenControls屬性。If you want to customize this behavior, you can use the RenderNonBreakingSpacesBetweenControls property.

您可以藉由NumericPagerFieldVisible屬性設定DataPagerfalse, 隱藏控制項中的物件。You can hide a NumericPagerField object in a DataPager control by setting the Visible property to false. 您無法控制下一頁頁面和上一頁按鈕的可見度。You cannot control the visibility of the next-page and previous-page buttons. 如果相關聯的資料控制項有其他可顯示的頁面, 控制項就會顯示它們。They are displayed by the control if the associated data control has additional pages available to display. 您可以使用ButtonCount屬性來指定要NumericPagerField在物件中顯示的按鈕數目。You can use the ButtonCount property to specify how many buttons are displayed in a NumericPagerField object. 每個按鈕都會對應到一個頁碼。Each button corresponds to a page number.

您可以藉由設定NextPageText屬性來設定下一頁按鈕的文字。You can set the text of the next-page button by setting the NextPageText property. 您可以使用PreviousPageText屬性來設定前一頁按鈕的文字。You can set the text of the previous-page button by using the PreviousPageText property.

當屬性設定為ButtonType.Image時, 您必須提供將針對下一頁和上一頁按鈕顯示之影像的 URL。 ButtonTypeWhen the ButtonType property is set to ButtonType.Image, you must provide the URL of an image that will be displayed for the next-page and previous page buttons. 您可以藉由設定NextPageImageUrlPreviousPageImageUrl屬性來執行這項操作。You do this by setting the NextPageImageUrl and PreviousPageImageUrl properties. 在此情況下, 會使用對應的 text 屬性作為影像的替代文字。In that case, the corresponding text property is used as the alternate text for the image. 例如, NextPageImageUrl屬性所指定的文字會顯示為 [下一頁影像] 按鈕的替代文字。For example, the text that is specified by the NextPageImageUrl property is displayed as the alternate text for the next-page image button. 在支援工具提示的瀏覽器上, 此文字也會顯示為對應按鈕的工具提示。On browsers that support tooltips, this text is also displayed as a tooltip for the corresponding button.

建構函式

NumericPagerField()

初始化 NumericPagerField 類別的新執行個體。Initializes a new instance of the NumericPagerField class.

屬性

ButtonCount

取得或設定要在 NumericPagerField 物件中顯示的按鈕數目。Gets or sets the number of buttons to display in a NumericPagerField object.

ButtonType

取得或設定要在頁面巡覽區欄位中顯示的按鈕類型。Gets or sets the button type to display in the pager field.

CurrentPageLabelCssClass

取得或設定用來設定目前頁碼樣式的階層式樣式表 (CSS) 類別。Gets or sets the cascading style sheet (CSS) class that is used to style the current page number.

DataPager

取得與 DataPagerField 物件關聯之資料頁面巡覽區的參考。Gets a reference to the data pager that the DataPagerField object is associated with.

(繼承來源 DataPagerField)
IsTrackingViewState

取得值,這個值表示 DataPagerField 物件是否正在追蹤它的檢視狀態變更。Gets a value that indicates whether the DataPagerField object is tracking its view-state changes.

(繼承來源 DataPagerField)
NextPageImageUrl

取得或設定針對 NumericPagerField 物件中的下一頁按鈕顯示之影像的 URL。Gets or sets the URL of an image that is displayed for the next-page button in the NumericPagerField object.

NextPageText

取得或設定為下一頁按鈕顯示的文字。Gets or sets the text that is displayed for the next-page button.

NextPreviousButtonCssClass

取得或設定階層式樣式表 (CSS) 類別,這個類別用來設定頁面巡覽區欄位之下一頁和上一頁按鈕的樣式。Gets or sets the cascading style sheet (CSS) class that is used to style the next-page and previous-page buttons of the pager field.

NumericButtonCssClass

取得或設定階層式樣式表 (CSS) 類別,這個類別用來設定頁面巡覽區欄位之頁碼按鈕的樣式。Gets or sets the cascading style sheet (CSS) class that is used to style the page-number buttons of the pager field.

PreviousPageImageUrl

取得或設定針對 NumericPagerField 物件中上一頁按鈕顯示之影像的 URL。Gets or sets the URL of an image that is displayed for the previous-page button in the NumericPagerField object.

PreviousPageText

取得或設定為上一頁按鈕顯示的文字。Gets or sets the text that is displayed for the previous-page button.

QueryStringHandled

取得或設定值,這個值表示是否已評估查詢字串欄位。Gets or sets a value that indicates whether the query string field has been evaluated.

(繼承來源 DataPagerField)
QueryStringValue

從要求的 URL 取得查詢字串欄位的值。Gets the value of the query string field from the URL of the request.

(繼承來源 DataPagerField)
RenderNonBreakingSpacesBetweenControls

取得或設定值,這個值表示是否要在控制項之間呈現不分行空格。Gets or sets a value that indicates whether non-breaking spaces will be rendered between controls.

ViewState

取得狀態資訊的字典,可讓您在相同頁面的多個要求之間儲存和還原 DataPagerField 物件的檢視狀態。Gets a dictionary of state information that enables you to save and restore the view state of a DataPagerField object across multiple requests for the same page.

(繼承來源 DataPagerField)
Visible

取得或設定值,這個值表示是否呈現資料頁面巡覽區欄位。Gets or sets a value that indicates whether a data pager field is rendered.

(繼承來源 DataPagerField)

方法

CloneField()

建立衍生自 DataPagerField 之目前物件的複本。Creates a copy of the current object that is derived from DataPagerField.

(繼承來源 DataPagerField)
CopyProperties(DataPagerField)

將目前 NumericPagerField 物件的屬性複製到指定的 DataPagerField 物件。Copies the properties of the current NumericPagerField object to the specified DataPagerField object.

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

為頁面巡覽區欄位建立使用者介面 (UI) 控制項,並將它們加入至指定的容器。Creates the user interface (UI) controls for the pager field object and adds them to the specified container.

CreateField()

建立並傳回 NumericPagerField 類別的新執行個體。Creates and returns a new instance of the NumericPagerField class.

Equals(Object)

判斷指定的物件是否等於目前的 NumericPagerField 物件。Determines whether the specified object is equal to the current NumericPagerField object.

GetHashCode()

做為 NumericPagerField 類別的雜湊函式。Serves as a hash function for the NumericPagerField class.

GetQueryStringNavigateUrl(Int32)

建立 URL,這個 URL 包含含有所指定頁碼的查詢字串欄位。Creates a URL that contains a query string field that has the specified page number.

(繼承來源 DataPagerField)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
HandleEvent(CommandEventArgs)

處理 NumericPagerField 物件中發生的事件並執行適當的動作。Handles events that occur in the NumericPagerField object and performs the appropriate action.

LoadViewState(Object)

還原先前儲存的檢視狀態資訊。Restores view-state information that was saved previously.

(繼承來源 DataPagerField)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
OnFieldChanged()

引發 FieldChanged 事件。Raises the FieldChanged event.

(繼承來源 DataPagerField)
SaveViewState()

儲存 DataPagerField 物件的檢視狀態變更。Saves the changes that were made to the DataPagerField object's view state.

(繼承來源 DataPagerField)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
TrackViewState()

DataPagerField 追蹤其檢視狀態變更,以將變更儲存在控制項的 ViewState 物件中,並在相同頁面的其他要求之間保存。Causes the DataPagerField object to track changes to its view state so that they can be stored in the control's ViewState property and persisted across requests for the same page.

(繼承來源 DataPagerField)

明確介面實作

IStateManager.IsTrackingViewState

取得值,這個值表示 DataPagerField 物件是否正在追蹤它的檢視狀態變更。Gets a value that indicates whether the DataPagerField object is tracking its view-state changes.

(繼承來源 DataPagerField)
IStateManager.LoadViewState(Object)

還原先前儲存的檢視狀態資訊。Restores view-state information that was saved previously.

(繼承來源 DataPagerField)
IStateManager.SaveViewState()

儲存 DataPagerField 物件的檢視狀態變更。Saves the changes that were made to the DataPagerField object's view state.

(繼承來源 DataPagerField)
IStateManager.TrackViewState()

DataPagerField 追蹤其檢視狀態變更,以將變更儲存在控制項的 ViewState 物件中,並在相同頁面的其他要求之間保存。Causes the DataPagerField object to track changes to its view state so that they can be stored in the control's ViewState property and persisted across requests for the same page.

(繼承來源 DataPagerField)

適用於

另請參閱