//要分页的DataTable
DataTable dt = new DataTable();
//分页结果集
DataTable dtRestult = dt.Clone();
//分页用的临时dt
DataTable dtTemp = dt.Clone();
//每页显示的条数
int i = 10;
//分页后的页数
int iPageCount = 0;
//要计算的列名
List<string> sComputer = new List<string>();
foreach (DataColumn dc in dtTemp.Columns)
{
switch (dc.DataType.FullName)
{
case "System.Int32":
case "System.Decimal":
case "System.Int64":
sComputer.Add(dc.ColumnName);
break;
}
}
for (int j = 0; j < dt.Rows.Count; j++)
{
dtTemp.Rows.Add(dt.Rows[j].ItemArray);
if ((j + 1) % i == 0 || j==dt.Rows.Count -1)
{
DataRow drTemp = dtTemp.NewRow();
foreach (string s in sComputer)
{
object obj = dtTemp.Compute("Sum(" + s + ")","");
drTemp[s] = obj;
}
//这里在实际用的时候换一下
drTemp[0] = " 合 计 ";
dtTemp.Rows.Add(drTemp);
dtRestult.Merge(dtTemp, true);
dtTemp = dt.Clone();
iPageCount++;
}
}