This documentation is archived and is not being maintained.

DataPager.Fields Property

Gets a collection of DataPagerField objects that represent the pager fields that are specified in a DataPager control.

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

public virtual DataPagerFieldCollection Fields { get; }

Property Value

Type: System.Web.UI.WebControls.DataPagerFieldCollection
A collection object that contains all the pager fields that are specified in the DataPager control.

The pager fields are displayed in the DataPager control in the order that the pager fields appear in the Fields collection. The following table shows the pager field classes that derive from the DataPagerField class and that can be used in the Fields collection.

Pager field type



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


Enables users to select a page of data by page number.


Enables you to create a custom paging UI.

To declaratively specify the pager fields for a DataPager control, put a Fields element inside the DataPager control. You can then list the pager fields you want to include between the opening and closing <Fields> tags.

You can programmatically add pager fields to the Fields collection. However, it is easier to list the pager fields declaratively in the DataPager control.

The following example shows how to declaratively add pager fields to the Fields collection of a DataPager control.

<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="" >
  <head id="Head1" runat="server">
    <title>DataPagerField Example</title>    
    <style type="text/css">
      	text-align: center; 
      	font: 13px Tahoma, Arial, Helvetica;
        border-bottom: solid 1px #FFA500;
    <form id="form1" runat="server">

      <h3>DataPagerField Example</h3>

      <asp:ListView ID="ProductsListView" 
          <table runat="server" id="tblProducts" width="350">
            <tr runat="server" id="itemPlaceholder" />
          <tr runat="server">
            <td class="item">
              <asp:Label ID="NameLabel" runat="server" 
                Text='<%#Eval("Name") %>' />
          <tr runat="server">
              <asp:Label ID="DescriptionLabel" runat="server" 
                Text='<%#Eval("Description")%>' />
          <tr runat="server">
      <br />

      <asp:DataPager runat="server" 
            <asp:Label runat="server" ID="CurrentPageLabel" 
              Text="<%# Container.TotalRowCount>0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0 %>" />
            <asp:Label runat="server" ID="TotalPagesLabel" 
              Text="<%# Math.Ceiling ((double)Container.TotalRowCount / Container.PageSize) %>" />
            <br /><br />

            ShowPreviousPageButton="false" />

            ButtonCount="10" />

            ShowPreviousPageButton="false" />

      <!-- 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')">


The following example shows how to use the Fields property to dynamically add a NextPreviousPagerField object to a DataPager control. This code example is part of a larger example provided for the NextPreviousPagerField constructor.

void Page_Load(Object sender, EventArgs e)

  // Dynamically generated field pagers need to be created only 
  // the first time the page is loaded.

  if (!IsPostBack)
    // Create a NextPreviousPagerField object to display
    // the buttons to navigate.
    NextPreviousPagerField pagerField = new NextPreviousPagerField();
    pagerField.ShowFirstPageButton = true;
    pagerField.ShowLastPageButton = true;
    pagerField.ButtonType = ButtonType.Button;

    // Add the pager field to the Fields collection of the
    // DataPager control.



.NET Framework

Supported in: 4, 3.5

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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