int totalNumber, iNumber;
double totalMoney, iMoney;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.EmptyDataRow)
{
DataRowView drvBasicCountInfor = (DataRowView)e.Row.DataItem;
iNumber = Convert.ToInt32(drvBasicCountInfor);
iMoney = Convert.Double(drvBasicCountInfor);
//生成总计
totalNumber += iNumber;
totalMoney += iMoney;
}
if(e.Row.RowType == DataControlRowType.Footer) //页脚
{
e.Row.Cells.Text = "总计";
e.Row.Cells.Text = string.Format("商品种类:{0}",totalNumber);
e.Row.Cells.Text = string.Format("合计金额:{0}",totalMoney);
}
}
需要设置GridView的ShowFooter=true .