Uredi

Deli z drugimi prek


DataPagerField Class

Definition

Serves as the base class for data pager field types, which represent a navigation control for the DataPager control.

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
Inheritance
DataPagerField
Derived
Implements

Examples

The following example shows how to use NextPreviousPagerField, NumericPagerField, and TemplatePagerField objects to display page navigation controls in a DataPager control. The objects are derived from the DataPagerField class.

<%@ 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>

Remarks

The DataPagerField class serves as the base class for all data pager field types. Data pager fields are used by the DataPager control to represent a navigation control.

Use the classes that are derived from DataPagerField to select which type of pager is displayed in the DataPager control. The following table lists available data pager field types.

Pager field type Description
NextPreviousPagerField Lets users navigate through data pages one page at a time, or to jump to the first or last page.
NumericPagerField Lets users select a page by page number.
TemplatePagerField Lets page developers create a custom paging UI.

You can derive from the DataPagerField class to create additional pager field types.

Notes to Implementers

When you inherit from the DataPagerField class, you must override the following members:

Constructors

DataPagerField()

Initializes a new instance of the DataPagerField class.

Properties

DataPager

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

IsTrackingViewState

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

QueryStringHandled

Gets or sets a value that indicates whether the query string field has been evaluated.

QueryStringValue

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

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.

Visible

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

Methods

CloneField()

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

CopyProperties(DataPagerField)

Copies the properties of the current object derived from DataPagerField to the specified DataPagerField object.

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

When overridden in a derived class, creates the user interface (UI) controls for the data pager field object and adds them to the specified container.

CreateField()

When overridden in a derived class, creates an empty object that is derived DataPagerField.

Equals(Object)

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

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetQueryStringNavigateUrl(Int32)

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

GetType()

Gets the Type of the current instance.

(Inherited from Object)
HandleEvent(CommandEventArgs)

When overridden in a derived class, handles events that occur in the data pager field object.

LoadViewState(Object)

Restores view-state information that was saved previously.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnFieldChanged()

Raises the FieldChanged event.

SaveViewState()

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

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.

Explicit Interface Implementations

IStateManager.IsTrackingViewState

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

IStateManager.LoadViewState(Object)

Restores view-state information that was saved previously.

IStateManager.SaveViewState()

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

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.

Applies to

See also