This documentation is archived and is not being maintained.

DataPagerCommandEventArgs Class

Provides data for the PagerCommand event of the TemplatePagerField class.


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

public class DataPagerCommandEventArgs : CommandEventArgs

The DataPagerCommandEventArgs type exposes the following members.

Public methodDataPagerCommandEventArgsInitializes a new instance of the DataPagerCommandEventArgs class.

Public propertyCommandArgumentGets the argument for the command. (Inherited from CommandEventArgs.)
Public propertyCommandNameGets the name of the command. (Inherited from CommandEventArgs.)
Public propertyItemGets the DataPagerFieldItem object that contains the DataPagerField object and the DataPagerField object's container DataPager object.
Public propertyNewMaximumRowsGets or sets the maximum number of records to display on each page of data.
Public propertyNewStartRowIndexGets or sets the index of the first record to display on a page of data.
Public propertyPagerFieldGets the DataPagerField object that contains the button that was clicked.
Public propertyTotalRowCountGets the total number of records to display.

Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

The TemplatePagerField object raises the PagerCommand event when a Button, LinkButton, or ImageButton control that is inside the pager field is clicked. These buttons are child controls that can be defined in the PagerTemplate template of a TemplatePagerField field.

During the event, you can perform tasks such as changing the number of rows that will be displayed or changing the index of the first item on the page.

For more information about how to handle events, see Consuming Events.

For a list of initial property values for an instance of the DataPagerCommandEventArgs class, see the DataPagerCommandEventArgs constructor.

The following example shows how to use the DataPagerCommandEventArgs object to enable the user to specify which page of data will be displayed in the ListView control. The DataPagerCommandEventArgs object is passed to the handler for the PagerCommand event of the TemplatePagerField class.

Security noteSecurity Note

This example contains a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

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

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

<script runat="server">

  protected void TemplatePagerField_OnPagerCommand(object sender, DataPagerCommandEventArgs e)
      // Get the new page number 
      TextBox PageNumberTextBox = (TextBox)e.Item.FindControl("PageNumberTextBox");
      int newPageNumber = -1;
        newPageNumber = Convert.ToInt32(PageNumberTextBox.Text.Trim());
      catch (FormatException)
        Message.Text = "Invalid page number.";
      catch (OverflowException)
        Message.Text = "Invalid page number.";

      int newIndex = (newPageNumber - 1) * e.Item.Pager.PageSize;
      //Verify if the new index is valid
      if (newIndex >= 0 && newIndex <= e.TotalRowCount)
        //Set the new start index and maximum rows
        e.NewStartRowIndex = newIndex;
        e.NewMaximumRows = e.Item.Pager.MaximumRows;
        Message.Text = "Invalid page number.";

  protected void Page_Load(object sender, EventArgs e)
    Message.Text = "";

<html xmlns="" >
  <head id="Head1" runat="server">
    <title>DataPagerCommandEventArgs Example</title>    
    <style type="text/css">
      	text-align: center;
      	font: 12px Arial, Helvetica, sans-serif;
          border: 1px solid #8b7e66;
          background: white;
          min-height: 19px;
          width: 33%;
        border: solid 1px #8b7e66;
        background: #f5deb3;
        width: 33%;
        min-height: 19px;
    <form id="form1" runat="server">

    <h3>DataPagerCommandEventArgs Example</h3>

      <asp:ListView ID="ContactsListView" 
          <table cellpadding="4" width="640px" id="tblProducts" runat="server">
            <tr runat="server" id="groupPlaceholder" />
          <asp:DataPager runat="server" 
              <asp:TemplatePagerField OnPagerCommand="TemplatePagerField_OnPagerCommand">
                  <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 />
                  Jump to page:
                  <asp:TextBox ID="PageNumberTextBox" runat="server" 
                    Text="<%# Container.TotalRowCount>0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0 %>" />                      
                  <asp:Button ID="GoButton" runat="server" Text="Go" />
                  <br /><br />
          <tr runat="server" id="ProductsRow">
            <td runat="server" id="itemPlaceholder" />
          <td class="item" runat="server">
            <asp:Label ID="NameLabel" runat="server" 
              Text='<%# Eval("LastName") + ", " + Eval("FirstName")%>' />
          <td class="alternatingItem" runat="server">
            <asp:Label ID="NameLabel" runat="server" 
              Text='<%# Eval("LastName") + ", " + Eval("FirstName")%>' />
      <br />      

      <asp:Label ID="Message"

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


.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.

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