1、GridView控件showfooter的属性=true
2、
int totalZJ, iZJ;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex != -1)
{
Label labId = (Label)e.Row.FindControl("labId");
labId.Text = (e.Row.RowIndex + 1 + AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1)).ToString();
}
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.EmptyDataRow)
{
DataRowView drvBasicCountInfor = (DataRowView)e.Row.DataItem;
iZJ = Convert.ToInt32(drvBasicCountInfor[2]);
//生成总计
totalZJ += iZJ;
}
if (e.Row.RowType == DataControlRowType.Footer) //页脚
{
e.Row.Cells[3].Text = "学分总计:";
e.Row.Cells[3].Style.Add("text-align", "right");
e.Row.Cells[4].Text = string.Format("{0}", totalZJ);
e.Row.Cells[4].Style.Add("text-align", "center");
} }