ASP.NET的gridview的页脚添加合计字段
转载于 “编程论坛”
int totalNumber, iNumber;
double totalMoney, iMoney;
protected void GRIDVIEW控件_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.EmptyDataRow)
{
DataRowView drvBasicCountInfor = (DataRowView)e.Row.DataItem;
iMoney = Convert.ToDouble(drvBasicCountInfor[6]);//6是第5列的数字
//生成总计
totalNumber += iNumber;
totalMoney += iMoney;
}
if (e.Row.RowType == DataControlRowType.Footer) //页脚
{
e.Row.Cells[5].Text = "总计金额";
e.Row.Cells[6].Text = string.Format("{0}", totalMoney);
}
}
别忘了 GridView控件showfooter的属性=true呀
int totalNumber, iNumber;
double totalMoney, iMoney;
protected void GRIDVIEW控件_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.EmptyDataRow)
{
DataRowView drvBasicCountInfor = (DataRowView)e.Row.DataItem;
iMoney = Convert.ToDouble(drvBasicCountInfor[6]);//6是第5列的数字
//生成总计
totalNumber += iNumber;
totalMoney += iMoney;
}
if (e.Row.RowType == DataControlRowType.Footer) //页脚
{
e.Row.Cells[5].Text = "总计金额";
e.Row.Cells[6].Text = string.Format("{0}", totalMoney);
}
}
别忘了 GridView控件showfooter的属性=true呀
