I cannot get a PagedDataSource
to use an IEnumerated collection of EntityCollection
objects as a datasource.
The PagedDataSource
accepts the collection as a datasource but then I can't use basic properties like CurrentPageIndex
and IsLastPage
etc.
My application breaks with the error Cannot compute Count for a data source that does not implement ICollection.
I tried doing
ICollection<Location> listlocations = Company.Locations;
but had no success.
What can I do?
Codesnippet
protected void loadBuildings()
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = Company.Locations;
pds.AllowPaging = true;
pds.PageSize = Convert.ToInt16(ddlPageSize.SelectedValue);
pds.CurrentPageIndex = CurrentPage;
lnkbtnNext.Enabled = !pds.IsLastPage;
lnkbtnPrevious.Enabled = !pds.IsFirstPage;
buildingsDataList.DataSource = pds;
buildingsDataList.DataBind();
}
I had to use the option AllowCustomPaging
and define my own pages because EntityCollection
doesn't support the ICollection
class.
I added the following code to define my pages/items
pds.VirtualCount = Company.Locations.Count();
pds.PageSize = 3;
pds.AllowCustomPaging = true;
as well as some other code in my pagegeneration method
for (int i = 0; i < (pds.VirtualCount/pds.PageSize);i++)