PageSize Property
Collapse the table of content
Expand the table of content

GridView.PageSize Property


Gets or sets the number of records to display on a page in a GridView control.

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

public virtual int PageSize { get; set; }

Property Value

Type: System.Int32

The number of records to display on a single page. The default is 10.

Exception Condition

The PageSize property is set to a value less than 1.

When the paging feature is enabled (by setting the AllowPaging property to true), use the PageSize property to specify the number of records to display on a single page.

The following example demonstrates how to use the PageSize property to display 15 records at a time in a GridView control.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" >
  <head runat="server">
    <title>GridView PageSize Example</title>
    <form id="form1" runat="server">

      <h3>GridView PageSize Example</h3>

      <asp:gridview id="CustomersGridView" 
        emptydatatext="No data available." 


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


.NET Framework
Available since 2.0
Return to top
© 2015 Microsoft