DataRow newDataRow = dt_Merge.NewRow();
newDataRow["ZiZhiText"] = "合计";
//循环dt
foreach (DataRow item in dt_Merge.Rows)
{
for (int j = 2; j < dt_Merge.Columns.Count; j++)
{
if (string.IsNullOrEmpty(newDataRow[j].ToString()) == true)
{
newDataRow[j] = 0;
}
// 计算所有行的除合计的其他列合计值
newDataRow[j] = Convert.ToDecimal(newDataRow[j]) + Convert.ToDecimal(item[j]);
}
}
dt_Merge.Rows.Add(newDataRow);
转载于:https://www.cnblogs.com/majing/archive/2013/03/21/2973290.html