Database Paging and Sorting with CSLA Part 2 - The CSLA Class

by Cliff 18. August 2007

Once your stored procedure is set up (see part 1) you can turn your attention to your CSLA class.   The class I am focusing on here is a read only list called "InfoList" that has a child class "InfoListItem".  This is a design taken directly from Rocky's book and sample application.  The class is declared as follows:

 public class InfoList : ReadOnlyListBase<InfoList, InfoListItem>, Csla.Core.IReportTotalRowCount

 In order to set up the grid view paging I am implementing the IReportTotalRowCount which is needed to get the total records satisfying your sp query.  The following is the implementation for the interface:

#region IReportTotalRowCount Members private int _totalRowCount;

/// <summary>

/// TotalRowCount - this property returns the total row count for the initial list that passed to the

/// constructor.

/// </summary>

int Csla.Core.IReportTotalRowCount.TotalRowCount


get { return _totalRowCount; }


//Property that can be used in UI to display total number of records
public int TotalRecordCount
get { return _totalRowCount; }


 Next is the code for the data access.  I have created a FilteredCriteria class that will handle the fields necessary to filter the resuts for paging:


private class FilteredCriteria


internal const int MAXROWS = int.MaxValue;

internal const string DEFAULTSORT = "Subject";

private int _pageIndex;

private int _pageSize;

private string _sort;

private string _searchString;

public string searchString


get { return _searchString; }


public string Sort


get { return _sort; }


public int PageIndex


get { return _pageIndex; }


public int PageSize


get { return _pageSize; }



public FilteredCriteria(int index, int pageSize, string sort, string searchString)


//this._pageIndex = GetPageIndex(index,numberOfRecords);

this._pageIndex = index;

this._pageSize = pageSize;

if (String.IsNullOrEmpty(sort))


this._sort = DEFAULTSORT;




this._sort = sort;


this._searchString = searchString;



Finally, the Fetch method is coded to pass in the values from the criteria class. This is just a standard sp call, the only additional code is that to get the total row count from the stored procedure and set the _totalRowCount field:

/Get total number of records for GridView paging



_totalRowCount = dr.GetInt32("TotalRowCount");

That completes the code required for the business class.  The final part is setting up the UI to leverage the pagin logic.  I will demonstrate this in Part 3.


September 4. 2009 02:13


Pingback from

Video – Reunión ALT .NET Café 29 De Agosto « BeyondNet

Comments are closed

Cliff Gray's Info

Cliff Gray

E-mail me Send mail



<<  May 2022  >>

View posts in large calendar


Download BlogEngine.NET

Download at CodePlex


The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2022