private double sum = 0;
//GridView控件的行数据绑定事件
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow) //如果是数据行
{
if (!string.IsNullOrEmpty(e.Row.Cells[2].Text)) //销售金额不为空
{
sum += Convert.ToDouble(e.Row.Cells[2].Text);//累计销售金额
}
}
else if (e.Row.RowType == DataControlRowType.Footer) //如果是脚注行
{
e.Row.Cells[0].Text = "总销售额:";
e.Row.Cells[2].Text = sum.ToString(); //将累计值添加到脚注行的销售金额单元格
}
}