#1
DataTable dt=GetDataTable();
Int pageSize=5000;
int count =dt.Rows.Count/pageSize;
for(int i=0;i<=count;i++)
{
DataTable dtNew=dt.AsEnumerable().Skip(i * pageSize).Take(pageSize).CopyToDataTable();
}
#2
public DataTable GetPagedTable(DataTable dt, int PageIndex, int PageSize)//PageIndex表示第幾頁,PageSize表示每頁的記錄數
{
if (PageIndex == 0)
return dt;//0頁代表每頁數據,直接返回
DataTable newdt = dt.Copy();
newdt.Clear();//copy dt的框架
int rowbegin = (PageIndex - 1) * PageSize;
int rowend = PageIndex * PageSize;
if (rowbegin >= dt.Rows.Count)
return newdt;//源數據記錄數小於等於要顯示的記錄,直接返回dt
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;
}
沒有留言:
張貼留言