Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
GridView Class
 AllowPaging Property
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
GridView..::.AllowPaging Property

Updated: November 2007

Gets or sets a value indicating whether the paging feature is enabled.

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

Visual Basic (Declaration)
Public Overridable Property AllowPaging As Boolean
Visual Basic (Usage)
Dim instance As GridView
Dim value As Boolean

value = instance.AllowPaging

instance.AllowPaging = value
C#
public virtual bool AllowPaging { get; set; }
Visual C++
public:
virtual property bool AllowPaging {
    bool get ();
    void set (bool value);
}
J#
/** @property */
public boolean get_AllowPaging()
/** @property */
public  void set_AllowPaging(boolean value)
JScript
public function get AllowPaging () : boolean
public function set AllowPaging (value : boolean)
ASP.NET
<asp:GridView AllowPaging="True|False" />

Property Value

Type: System..::.Boolean

true if the paging feature is enabled; otherwise, false. The default is false.

Instead of displaying all the records in the data source at the same time, the GridView control can automatically break the records up into pages. If the data source supports the paging capability, the GridView control can take advantage of that and provide built-in paging functionality. The paging feature can be used with any data source object that supports the System.Collections..::.ICollection interface or a data source that supports paging capability.

To enable the paging feature, set the AllowPaging property to true. By default, the GridView control displays 10 records on a page at a time. You can change the number of records displayed on a page by setting the PageSize property. To determine the total number of pages required to display the data source contents, use the PageCount property. You can determine the index of the currently displayed page by using the PageIndex property.

When paging is enabled, an additional row called the pager row is automatically displayed in the GridView control. The pager row contains controls that allow the user to navigate to the other pages. You can control the settings of the pager row (such as the pager display mode, the number of page links to display at a time, and the pager control's text labels) by using the PagerSettings property. The pager row can be displayed at the top, bottom, or both the top and bottom of the control by setting the Position property. You can also select from one of four built-in pager display modes by setting the Mode property. The following table describes the built-in display modes.

Mode

Description

PagerButton.NextPrevious

A set of pagination controls consisting of previous and next buttons.

PagerButton.NextPreviousFirstLast

A set of pagination controls consisting of previous, next, first, and last buttons.

PagerButton.Numeric

A set of pagination controls consisting of numbered link buttons to access pages directly. This is the default mode.

PagerButton.NumericFirstLast

A set of pagination controls consisting of numbered and first and last link buttons.

To control the appearance of the pager row (including its background color, font color, and position), use the PagerStyle property.

Note:

The GridView control automatically hides the pager row when the data source contains only one page of records.

The GridView control also enables you to define a custom template for the pager row. For more information about creating a custom pager row template, see PagerTemplate.

The GridView control provides several events that you can use to perform a custom action when paging occurs. The following table lists the available events.

Event

Description

PageIndexChanged

Occurs when one of the pager buttons is clicked, but after the GridView control handles the paging operation. This event is commonly used when you need to perform a task after the user navigates to a different page in the control.

PageIndexChanging

Occurs when one of the pager buttons is clicked, but before the GridView control handles the paging operation. This event is often used to cancel the paging operation.

TopicLocation
How to: Enable Default Paging in the GridView Web Server ControlBuilding ASP .NET Web Applications in Visual Studio
How to: Enable Default Paging in the GridView Web Server ControlBuilding ASP .NET Web Applications in Visual Studio

The following example demonstrates how to use the AllowPaging property to declaratively enable the paging feature in the GridView control.

Visual Basic
<%@ Page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
  <head runat="server">
    <title>GridView AllowPaging Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>GridView AllowPaging Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        emptydatatext="No data available." 
        allowpaging="true" 
        runat="server">

        <pagersettings mode="Numeric"
          position="Bottom"           
          pagebuttoncount="10"/>

        <pagerstyle backcolor="LightBlue"
          height="30px"
          verticalalign="Bottom"
          horizontalalign="Center"/>

      </asp:gridview>

      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>

    </form>
  </body>
</html>


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
  <head runat="server">
    <title>GridView AllowPaging Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>GridView AllowPaging Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        emptydatatext="No data available." 
        allowpaging="true" 
        runat="server">

        <pagersettings mode="Numeric"
          position="Bottom"           
          pagebuttoncount="10"/>

        <pagerstyle backcolor="LightBlue"
          height="30px"
          verticalalign="Bottom"
          horizontalalign="Center"/>

      </asp:gridview>

      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>

    </form>
  </body>
</html>


Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker