首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

.netASP中GridView有关问题

2013-01-25 
.netASP中GridView问题现在做报表要导出GridView为Excel其他的我都弄好了!只是在GridView结尾,我加了一行“

.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>");

热点排行