Datableページング
5794 ワード
using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
/// <summary>
///Page
/// </summary>
public class PageList
{
public PageList()
{
//
//TODO:
//
}
/// <summary>
/// DataTable , 1
/// </summary>
/// <param name="dt"></param>
/// <param name="PageIndex"></param>
/// <param name="PageSize"></param>
/// <returns></returns>
public static DataTable GetPagedTable(DataTable dt, int PageIndex, int PageSize)
{
if (PageIndex == 0)
return dt;
DataTable newdt = dt.Copy();
newdt.Clear();
int rowbegin = (PageIndex - 1) * PageSize;
int rowend = PageIndex * PageSize;
if (rowbegin >= dt.Rows.Count)
return newdt;
if (rowend > dt.Rows.Count)
rowend = dt.Rows.Count;
for (int i = rowbegin; i <= rowend - 1; i++)
{
DataRow newdr = newdt.NewRow();
DataRow dr = dt.Rows[i];
foreach (DataColumn column in dt.Columns)
{
newdr[column.ColumnName] = dr[column.ColumnName];
}
newdt.Rows.Add(newdr);
}
return newdt;
}
/// <summary>
///
/// </summary>
/// <param name="sumCount"> </param>
/// <param name="pageSize"> </param>
/// <returns></returns>
public static int getPageCount(int sumCount, int pageSize)
{
int page = sumCount / pageSize;
if (sumCount % pageSize > 0)
{
page = page + 1;
}
return page;
}
}
ソース:http://blog.csdn.net/willianyy/article/details/5734486