ExtendedObjectDataSource samples

Product Information

Select method to extract the total row count for Paging

In this sample we use the ExtendedObjectDataSource to show paged data in a GridView.With the ObjectDataSource and the CompatObjectDataSource, if we have enabled paging, the SelectCountMethod will be called to retrieve the total row count. This has several drawbacks:

  • Two calls have to be performed in order to show the data, one for the SelectMethod and the other for the SelectCountMethod.
  • Most of the paging methods let us retrieve the total row count in the same data base query where we ask for data, so even if we get the total row count in the SelectMethod, we have to return it in the SelectCountMethod.
  • The previous point forces us save the total row count to return it later, so the Select method could not be static.

The TotalRowCountParameterName of the ExtendedObjectDataSource let us specify an output parameter for the SelectMethod in order to retrieve the total row count in case we are using paging, so there is no need for the SelectCountMethod.

1Product 1Full description for product number 12
2Product 2Full description for product number 24
3Product 3Full description for product number 36
4Product 4Full description for product number 48

Sample source code

The ASPX file for this sample is:

<%@ Page Language="C#" MasterPageFile="~/DefaultMaster.master" AutoEventWireup="true" CodeFile="SelectMethod.aspx.cs" Inherits="SelectMethod" Title="Select Method to extract total row count" %>


<%@ Register Assembly="ExtendedObjectDataSource" Namespace="Manu.Web.UI.WebControls" TagPrefix="manu" %>


<asp:Content ID="Content1" ContentPlaceHolderID="Content" Runat="Server">

    <h1>Select method to extract the total row count for Paging</h1>


    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"

        AutoGenerateColumns="False" CssClass="gridview" BackColor="#335789"

        BorderColor="#133769" BorderStyle="Solid" BorderWidth="1px"

        DataSourceID="ObjectDataSource1" PageSize="4">


            <asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" />

            <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />

            <asp:BoundField DataField="Description" HeaderText="Description" 
="Description" />

            <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />


        <RowStyle BackColor="White" ForeColor="#436799" />

        <HeaderStyle ForeColor="White" />

        <PagerStyle ForeColor="White" />


    <manu:ExtendedObjectDataSource ID="ObjectDataSource1" runat="server"
="True" MaximumRowsParameterName="maxRows" 
="original_{0}" SelectMethod="LoadAll"
="sortedBy" StartRowIndexParameterName="startIndex" 
          TotalRowCountParameterName="totalRowCount" TypeName



The code-behind file (ASPX.CS) is:

using System;


public partial class SelectMethod : System.Web.UI.Page


    protected void Page_Load(object sender, EventArgs e)