您的位置:首页 > 其它

List<T> 分页方式,泛型分页方式

2011-07-26 10:51 323 查看
List

protected List<T> ListPager<T>(List<T> DataSource, int CurrentPageIndex, int PageSize, string FilterExpression, ref int count)
{
count = 0;
if (DataSource == null || DataSource.Count == 0)
return DataSource;
count = DataSource.Count;
if (string.IsNullOrEmpty(FilterExpression))
{
int startIndex = CurrentPageIndex * PageSize;
if (startIndex + PageSize > DataSource.Count)
{
PageSize = DataSource.Count - startIndex;
}
return DataSource.GetRange(startIndex, PageSize);
}
else
{
DataTable dt = KingLib.DataHelper.ListToDataTable<T>(DataSource);
DataView dv = dt.DefaultView;
dv.RowFilter = FilterExpression;
List<T> NewDataSource = KingLib.DataHelper.DataTableToList<T>(dv.ToTable());
count = NewDataSource.Count;
int startIndex = CurrentPageIndex * PageSize;
if (startIndex + PageSize > NewDataSource.Count)
{
PageSize = NewDataSource.Count - startIndex;
}
return NewDataSource.GetRange(startIndex, PageSize);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: