DataPager Class

Provides paging functionality for data-bound controls that implement the IPageableItemContainer interface, such as the ListView control.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

[ToolboxBitmapAttribute(typeof(DataPager), "DataPager.ico")]
[ThemeableAttribute(true)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class DataPager : Control, IAttributeAccessor, 
	INamingContainer, ICompositeControlDesignerAccessor
<asp:DataPager />

The DataPager class is used to page data and to display navigation controls for data-bound controls that implement the IPageableItemContainer interface. (An example of a control that implements the interface is the ListView control.)

You can associate the DataPager control with the data-bound control by using the PagedControlID property. Alternatively, you can put the DataPager control inside the data-bound control hierarchy. For example, in the ListView control, you can put the DataPager control inside the ListView.LayoutTemplate template.

You can customize the number of items that are displayed for each page of data by changing the PageSize property. You can also change the way a page is submitted to the server by setting the QueryStringField property.

Pager Fields

In order for the DataPager control to display navigation controls, you must add pager fields to the control. The pager fields derive from the DataPagerField class. The following table lists the pager field types that you can use.

Pager field type

Description

NextPreviousPagerField

Enables users to navigate through pages one page at a time, or to jump to the first or last page.

NumericPagerField

Enables users to select a page by page number.

TemplatePagerField

Enables you to create a custom paging UI.

To declaratively add pager fields to the DataPager control, add a Fields element to the DataPager control. You can then add the pager fields to the Fields element. The pager fields are added to the Fields collection in the order that they appear in the Fields element. The Fields collection enables you to programmatically manage the pager fields in the DataPager control.

Page Properties

The following table lists read-only properties of the DataPager control that specify characteristics of the page of data. These properties are usually used for binding expressions in the TemplatePagerField object.

Property

Description

MaximumRows

The maximum number of records that are displayed for each page of data.

StartRowIndex

The index of the first record that is displayed on a page of data.

TotalRowCount

The total number of records that are available in the underlying data source.

Accessibility

The default markup that is rendered default for this control might not comply with accessibility standards, such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.

TopicLocation
Walkthrough: Displaying, Paging, and Sorting Data Using the ListView Web Server ControlBuilding ASP .NET Web Applications in Visual Studio

The following example shows how to add paging functionality to a ListView control. This example contains two DataPager controls that are used to page through data of the same 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>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">&nbsp;</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>

System.Object
  System.Web.UI.Control
    System.Web.UI.WebControls.DataPager

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft