No record count using CSLADataSource

No record count using CSLADataSource

Old forum URL: forums.lhotka.net/forums/t/6908.aspx


Chaz4Code posted on Wednesday, May 06, 2009

I have a csladatasource pointing to a readOnlyListBase object.  While it binds fine unlike the other datasource controls there is no way to specify the RecordCount method.  I have implemented the IReportTotalRowCount interface on my business object but the TotalRowCount property is never called.

I would think given the obvious need to not load every record at once the answer is simple but currently I've had no luck finding any explanation on how IReportTotalRowCount is supposed to work and as a result my gridview thinks the total row count is how many items I returned from my query.

Any suggests would be appreciated.

thanks.

 

RockfordLhotka replied on Wednesday, May 06, 2009

The basic approach is to take the arguments object passed into the select method from data binding, and pass some or all of that information through your criteria object to the DataPortal_Fetch() method so you can do the sorting/filtering/paging at the database level.

When you do this, it is your responsibility, in the factory method, to report the total row count, and provide a paged subset of the overall data.

  1. Implement IReportTotalRowCount in your collection
  2. Accept the SelectObjectArgs parameter in your static factory method
  3. Include the SelectObjectArgs value as a field in your criteria object
  4. Use the starting row indiex and page size values from the SelectObjectArgs in your DataPortal_Fetch() method to load the collection with only the specfiied page of data
  5. In your DataPortal_Fetch() method, load the total number of rows of data available
  6. Set the TypeSupportsPaging property of your CslaDataSource control to true
  7. Enable paging in the GridView control

Full coverage of sorting/filtering/paging is in the CSLA .NET Version 2.1 Handbook ebook from http://store.lhotka.net. But you need a factory method something like this:

public static MyList GetPage(Csla.Web.SelectObjectArgs args)
{
  return DataPortal.Fetch<MyList>(new SingleCriteria<MyList, Csla.Web.SelectObjectArgs)(args));
}

 

Chaz4Code replied on Thursday, May 07, 2009

Thanks for your quick response Rocky.  Much appreciated.

Copyright (c) Marimer LLC