先上图片,看看是不是你需要的?
关键代码:
protected void _gvGuest_RowDataBound(object sender, GridViewRowEventArgs e)
{
int count = _gvGuest.Rows.Count;
if (e.Row.RowIndex >= 0)
{
sumRoom += Convert.ToDouble(e.Row.Cells[5].Text);
sumJe += Convert.ToDouble(e.Row.Cells[6].Text);
sumNgtKey += Convert.ToDouble(e.Row.Cells[7].Text);
sumDyKey += Convert.ToDouble(e.Row.Cells[8].Text);
sumResvNum += Convert.ToDouble(e.Row.Cells[9].Text);
sumCZL += Convert.ToDouble(e.Row.Cells[10].Text);
sumRevper += Convert.ToDouble(e.Row.Cells[11].Text);
sumPJFJ += Convert.ToDouble(e.Row.Cells[12].Text);
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[5].Text = "汇总房间数:" + sumRoom.ToString();
e.Row.Cells[6].Text = "汇总房金:" + sumJe.ToString();
e.Row.Cells[7].Text = "汇总过夜房:" + sumNgtKey.ToString();
e.Row.Cells[8].Text = "汇总日房:" + sumDyKey.ToString();
e.Row.Cells[9].Text = "汇总使用房间数:" + sumResvNum.ToString();
e.Row.Cells[10].Text = "平均出租率:" + (sumCZL / count).ToString("0.00") + "%";
e.Row.Cells[11].Text = "平均Revpar:" + (sumRevper / count).ToString("0.00") + "%";
e.Row.Cells[12].Text = "平均房价:" + (sumPJFJ / count).ToString("0.00") + "%";
}
}
补充说明:
①GridView的ShowFooter="true"
②颜色:<HeaderStyle Font-Bold="True" ForeColor="Black" HorizontalAlign="Center" />
<FooterStyle Font-Bold="true" ForeColor="Black" HorizontalAlign="Center" />
③GridView的OnRowDataBound="_gvGuest_RowDataBound"