码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-04-30 12:05:41      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

 来自:http://blog.csdn.net/soulscarrier

    protected List ListPager(List 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(DataSource);

  DataView dv = dt.DefaultView;

  dv.RowFilter = FilterExpression;

  List NewDataSource = KingLib.DataHelper.DataTableToList(dv.ToTable());

  count = NewDataSource.Count;

  int startIndex = CurrentPageIndex * PageSize;

  if (startIndex + PageSize > NewDataSource.Count)

  {

  PageSize = NewDataSource.Count - startIndex;

  }

  return NewDataSource.GetRange(startIndex, PageSize);

  }

  }

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

标签:

原文地址:http://www.cnblogs.com/Soulcarriers/p/4468277.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!