ObjectDataSource.EnablePaging Property

Gets or sets a value that indicates whether the data source control supports paging through the set of data that it retrieves.

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

public bool EnablePaging { get; set; }
/** @property */
public boolean get_EnablePaging ()

/** @property */
public void set_EnablePaging (boolean value)

public function get EnablePaging () : boolean

public function set EnablePaging (value : boolean)

Not applicable.

Property Value

true if the data source control supports paging through the data it retrieves; otherwise, false.

Paging by the ObjectDataSource control is handled by setting the EnablePaging, StartRowIndexParameterName, MaximumRowsParameterName, and SelectCountMethod properties of the ObjectDataSource and defining a select method in the business object with the proper parameters. When the EnablePaging property is set to true, the SelectParameters collection includes two additional parameters for the first row that is requested and the number of rows that are requested. These two parameters are named as defined by the StartRowIndexParameterName and MaximumRowsParameterName properties. The Select method should return the requested number of rows, starting at the specified index. Because the data might not divide evenly by the page size, the last page might contain fewer rows. Thus, the number of rows that are requested is actually the maximum number of rows that are returned.


If you are not familiar with the Data Access features in ASP.NET 2.0, you should read some of these topics before continuing:

When paging is enabled on the associated data-bound control, the data-bound control calls the Select method with the start index and number of rows that are required. Additionally, if the SelectCountMethod property is set, the data-bound control calls the method before rendering the pager controls. For example, if a GridView control has paging enabled with a page size of 5, and the method that is specified by the SelectCountMethod property returns 20, only 4 pages are displayed in the pager.

The EnablePaging property delegates to the EnablePaging property of the ObjectDataSourceView object.

This section contains two code examples. The first code demonstrates how to implement a type that enables paging. The second code example demonstrates how to create an instance of the ObjectDataSource class and set properties.

The following code example demonstrates how to implement a type that enables paging. The PagingData.Select method takes two parameters, startRowIndex and maximumRows. The PagingData class also defines a method named SelectCount, which returns the total number of rows in the data. The following code shows the PagingData class:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Samples.AspNet.CS

	public class PagingData

		public PagingData()


		static DataTable table;

		private DataTable CreateData()
			table = new DataTable();
			table.Columns.Add("Name", typeof(string));
			table.Columns.Add("Number", typeof(int));
			return table;

		public DataTable SelectMethod(int startRowIndex, int maximumRows)
			int current;
			for (int i = 0; i < maximumRows; i++)
				current = i + startRowIndex;
				table.Rows.Add(new object[] { "Number" + current.ToString(), current });
			return table;

		public int SelectCount()
			return 20;

		public int Insert(NewData newRecord)
			table.Rows.Add(new object[] { newRecord.Name, newRecord.Number });
			return 1;

    public class NewData
	private string nameValue;
	private int numberValue;

	public string Name
		get { return nameValue; }
		set { nameValue = value; }

	public int Number
		get { return numberValue; }
		set { numberValue = value; }


The following code example demonstrates how to create an instance of the ObjectDataSource class and sets the following properties for paging:

  • The TypeName property is set to PagingData.

  • The SelectCountMethod is set to SelectCount.

  • The EnablePaging is set to true.

The values for the MaximumRowsParameterName and StartRowIndexParameterName properties are left as their defaults, maximumRows and startRowIndex, respectively.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<script runat="server">


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
        <asp:GridView ID="GridView1" 

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0