/// <Summary>
/// Pagination the able and generate a new datatable
/// </Summary>
/// <Param name = "DT"> Original datatable </Param>
/// <Param name = "pageindex"> Page N required </Param>
/// <Param name = "pagesize"> Number of pages per page </Param>
/// <Returns> New able </Returns>
Public Datatable getpagedtable (datatable DT, Int Pageindex, Int Pagesize)
{
If (Pageindex = 0 )
{
Return DT;
}
Datatable newdt = DT. Copy ();
Newdt. Clear ();
// Start row
Int Rowbegin = (Pageindex - 1 ) * Pagesize;
// End row
Int Rowend = Pageindex * Pagesize;
If(Rowbegin> =DT. Rows. Count)
{
ReturnNewdt;
}
If (Rowend > DT. Rows. Count)
{
Rowend = DT. Rows. count;
}
// Generate a new able
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;
}