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; }
}

 #endregion

 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:

[Serializable]

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;

}

else

{

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

dr.NextResult();

dr.Read();

_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.

Related posts

Comments

September 4. 2009 02:13

pingback

Pingback from beyondnet.codesol.info

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

beyondnet.codesol.info

Comments are closed

Cliff Gray's Info

Cliff Gray
Developer/Founder GrayTechnology.com.

E-mail me Send mail

Authors

Calendar

<<  July 2019  >>
MoTuWeThFrSaSu
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Blogroll

Download BlogEngine.NET

Download at CodePlex

Disclaimer

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

© Copyright 2019

Subscribe