DataPager.PageSize Property


Gets or sets the number of records that are displayed for each page of data.

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

public int PageSize { get; set; }

Property Value

Type: System.Int32

The number of records that are displayed for each page of data. The default is 10.

Exception Condition

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

Use the PageSize property to specify the size of a page of data.

If you have multiple DataPager controls in a page that are bound to the same ListView control, be sure to set the PageSize property of these controls to the same value. If the DataPager controls are set to use different page sizes, the last DataPager control to be initialized determines the actual page size of the ListView control.

The following example shows how to declaratively set the PageSize property in a DataPager control and how to dynamically change its value.

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

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

<script runat="server">

  protected void ResultsList_SelectedIndexChanged(object sender, EventArgs e)
    // Set the page size with the value
    // selected in the DropDownList object
    VendorsDataPager.PageSize = Convert.ToInt32(ResultsList.SelectedValue);

<html xmlns="" >
  <head id="Head1" runat="server">
    <title>DataPager PageSize Example</title>
    <form id="form1" runat="server">

      <h3>DataPager PageSize Example</h3>

      <table border="0" width="640px">
          <td align="left">
            <asp:Label id="ResultsLabel" runat="server" 
              AssociatedControlID="ResultsList" Text="Results per page:" />            
            <asp:DropDownList runat="server" id="ResultsList" 
              OnSelectedIndexChanged="ResultsList_SelectedIndexChanged" AutoPostBack="true">              
              <asp:ListItem Value="10"  />
              <asp:ListItem Value="15" Selected="True" />
              <asp:ListItem Value="20" />
          <td align="right">
            <asp:DataPager ID="VendorsDataPager" runat="server" 
              PagedControlID="VendorsListView" PageSize="15">
                <asp:NumericPagerField />
      <br />

      <asp:ListView ID="VendorsListView" 
          <table cellpadding="2" width="640px">
              <tr runat="server" id="itemPlaceholder"></tr>
          <tr runat="server">
              <asp:Label ID="VendorIDLabel" runat="server" Text='<%# Eval("VendorID") %>' />
              <asp:Label ID="AccountNumberLabel" runat="server" Text='<%# Eval("AccountNumber") %>' />
              <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
            <td align="center">
              <asp:CheckBox ID="PreferredCheckBox" runat="server" 
                Checked='<%# Eval("PreferredVendorStatus") %>' Enabled="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="VendorsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"            
        SelectCommand="SELECT VendorID, AccountNumber, Name, PreferredVendorStatus 
          FROM Purchasing.Vendor WHERE (ActiveFlag = 1)" >

.NET Framework
Available since 3.5
Return to top