.netASP中GridView问题
现在做报表要导出GridView为Excel
其他的我都弄好了!
只是在GridView结尾,我加了一行“合计”
DataTable dt = (DataTable)Session["AP_Available_Table"];
if (dt != null)
{
decimal sum1 = 0;
foreach (DataRow row in dt.Rows)
{
sum1 += Convert.ToDecimal(Convert.ToString(row[1]).Replace("%",""))/100;
}
e.Row.Cells[0].Text = "合计:";
e.Row.Cells[1].Text = (sum1 / (dt.Rows.Count)).ToString("p2");
}
然后问题是,我导出的报表中没有“合计”这一行,请问我应该要怎么加上这一行!
报表的内容行是这样导出的!
HttpContext.Current.Response.Write("<Row>");
for (int c = 0; c < columns; c++)
{
HttpContext.Current.Response.Write("<Cell ss:StyleID='border'><Data ss:Type='String'>" + dt.Rows[j][c].ToString()+ "</Data></Cell>");
}
HttpContext.Current.Response.Write("</Row>");
------解决方案--------------------GridView1.FooterRow.Cells[c].ToString()
------解决方案--------------------在导出最后再加上下面代码(即在j循环结束)加
//加上下面代码
HttpContext.Current.Response.Write("<Row>");
HttpContext.Current.Response.Write("<Cell ss:StyleID='border'><Data ss:Type='String'>合计</Data></Cell>");
HttpContext.Current.Response.Write("<Cell ss:StyleID='border'><Data ss:Type='String'>" + (sum1 / (dt.Rows.Count)).ToString("p2") +"</Data></Cell>");
for (int c = 2; c < columns; c++)
{
HttpContext.Current.Response.Write("<Cell ss:StyleID='border'><Data ss:Type='String'> </Data></Cell>");
}
HttpContext.Current.Response.Write("<Row>");