Edit

Kongsi melalui


NumericPagerField Class

Definition

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
Inheritance
NumericPagerField

Examples

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="< Prev"
              NextPageText="Next >"
              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="< Prev"
              NextPageText="Next >"
              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>

Remarks

The NumericPagerField class displays navigation controls in a DataPager control. 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. 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.

You can customize the appearance of the NumericPagerField object by using the properties that are listed in the following table.

Property Description
CurrentPageLabelCssClass The CSS class for the current page number.
NextPreviousButtonCssClass The CSS class for the next-page and previous-page buttons.
NumericButtonCssClass The CSS class for the buttons that represent the page numbers.

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 A Button control.
ButtonType.Image An ImageButton control.
ButtonType.Link A LinkButton control.

The controls inside the NumericButtonCssClass object are rendered with non-breaking spaces between them. If you want to customize this behavior, you can use the RenderNonBreakingSpacesBetweenControls property.

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. You can use the ButtonCount property to specify how many buttons are displayed in a NumericPagerField object. Each button corresponds to a page number.

You can set the text of the next-page button by setting the NextPageText property. You can set the text of the previous-page button by using the PreviousPageText property.

When 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. You do this by setting the NextPageImageUrl and PreviousPageImageUrl properties. In that case, the corresponding text property is used as the alternate text for the image. 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.

Constructors

NumericPagerField()

Initializes a new instance of the NumericPagerField class.

Properties

ButtonCount

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

Gets or sets the cascading style sheet (CSS) class that is used to style the current page number.

DataPager

Gets a reference to the data pager that the DataPagerField object is associated with.

(Inherited from DataPagerField)
IsTrackingViewState

Gets a value that indicates whether the DataPagerField object is tracking its view-state changes.

(Inherited from DataPagerField)
NextPageImageUrl

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

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

Gets or sets the cascading style sheet (CSS) class that is used to style the page-number buttons of the pager field.

PreviousPageImageUrl

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.

(Inherited from DataPagerField)
QueryStringValue

Gets the value of the query string field from the URL of the request.

(Inherited from DataPagerField)
RenderNonBreakingSpacesBetweenControls

Gets or sets a value that indicates whether non-breaking spaces will be rendered between controls.

ViewState

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.

(Inherited from DataPagerField)
Visible

Gets or sets a value that indicates whether a data pager field is rendered.

(Inherited from DataPagerField)

Methods

CloneField()

Creates a copy of the current object that is derived from DataPagerField.

(Inherited from DataPagerField)
CopyProperties(DataPagerField)

Copies the properties of the current NumericPagerField object to the specified DataPagerField object.

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

Creates the user interface (UI) controls for the pager field object and adds them to the specified container.

CreateField()

Creates and returns a new instance of the NumericPagerField class.

Equals(Object)

Determines whether the specified object is equal to the current NumericPagerField object.

GetHashCode()

Serves as a hash function for the NumericPagerField class.

GetQueryStringNavigateUrl(Int32)

Creates a URL that contains a query string field that has the specified page number.

(Inherited from DataPagerField)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
HandleEvent(CommandEventArgs)

Handles events that occur in the NumericPagerField object and performs the appropriate action.

LoadViewState(Object)

Restores view-state information that was saved previously.

(Inherited from DataPagerField)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnFieldChanged()

Raises the FieldChanged event.

(Inherited from DataPagerField)
SaveViewState()

Saves the changes that were made to the DataPagerField object's view state.

(Inherited from DataPagerField)
ToString()

Returns a string that represents the current object.

(Inherited from Object)
TrackViewState()

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.

(Inherited from DataPagerField)

Explicit Interface Implementations

IStateManager.IsTrackingViewState

Gets a value that indicates whether the DataPagerField object is tracking its view-state changes.

(Inherited from DataPagerField)
IStateManager.LoadViewState(Object)

Restores view-state information that was saved previously.

(Inherited from DataPagerField)
IStateManager.SaveViewState()

Saves the changes that were made to the DataPagerField object's view state.

(Inherited from DataPagerField)
IStateManager.TrackViewState()

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.

(Inherited from DataPagerField)

Applies to

See also