// 獲取指定頁。
public static DataSet GetDsPage(int npgNo,int npgSize,DataSet ds,ref int npgCount,ref int nRecordCount)
{ //參數依次意思爲 當前頁, 每頁記錄數, 總共頁數, 總共記錄數
//PgSize小於1,則不分頁
if (npgSize < 1 || ds == null || ds.Tables.Count < 1)
{
return ds;
}
nRecordCount = ds.Tables[0].Rows.Count;
int npgStart = (npgNo - 1) * npgSize ;
//每一頁的開始記錄的位置
int npgEnd =npgStart + npgSize - 1;
//每一頁的結束記錄的位置
int nCount = ds.Tables[0].Rows.Count ;
//計算總共頁數
npgCount = (int)(nCount / npgSize);
if((nCount % npgSize) > 0)
{
npgCount = npgCount + 1;
}
//計算總共頁數
if(npgStart > nCount)
{
return null ;
}
//到達最後一頁則總共記錄數爲 結束記錄數
if(npgEnd > nCount)
{
npgEnd = nCount ;
}
//去掉前面不必要的記錄
for(int i = 0;i < npgStart;i++)
{
ds.Tables[0].Rows.RemoveAt(0);
}
//去掉後面不必要的記錄
for(int j = 1;j < nCount - npgEnd;j++)
{
ds.Tables[0].Rows.RemoveAt(npgSize);
}
return ds;
}