Gridview求和,求平均数,非常简单实用

来源:互联网 发布:js date获取日期 编辑:程序博客网 时间:2024/05/01 22:26
  1. protected void _gvGuest_RowDataBound(object sender, GridViewRowEventArgs e)  
  2.         {  
  3.             int count = _gvGuest.Rows.Count;  
  4.   
  5.             if (e.Row.RowIndex >= 0)  
  6.             {  
  7.                 sumRoom += Convert.ToDouble(e.Row.Cells[5].Text);  
  8.                 sumJe += Convert.ToDouble(e.Row.Cells[6].Text);  
  9.                 sumNgtKey += Convert.ToDouble(e.Row.Cells[7].Text);  
  10.                 sumDyKey += Convert.ToDouble(e.Row.Cells[8].Text);  
  11.                 sumResvNum += Convert.ToDouble(e.Row.Cells[9].Text);  
  12.   
  13.                 sumCZL += Convert.ToDouble(e.Row.Cells[10].Text);  
  14.                 sumRevper += Convert.ToDouble(e.Row.Cells[11].Text);  
  15.                 sumPJFJ += Convert.ToDouble(e.Row.Cells[12].Text);  
  16.             }  
  17.             else if (e.Row.RowType == DataControlRowType.Footer)  
  18.             {  
  19.                 e.Row.Cells[5].Text = "汇总房间数:" + sumRoom.ToString();  
  20.                 e.Row.Cells[6].Text = "汇总房金:" + sumJe.ToString();  
  21.                 e.Row.Cells[7].Text = "汇总过夜房:" + sumNgtKey.ToString();  
  22.                 e.Row.Cells[8].Text = "汇总日房:" + sumDyKey.ToString();  
  23.                 e.Row.Cells[9].Text = "汇总使用房间数:" + sumResvNum.ToString();  
  24.   
  25.                 e.Row.Cells[10].Text = "平均出租率:" + (sumCZL / count).ToString("0.00") + "%";  
  26.                 e.Row.Cells[11].Text = "平均Revpar:" + (sumRevper / count).ToString("0.00") + "%";  
  27.                 e.Row.Cells[12].Text = "平均房价:" + (sumPJFJ / count).ToString("0.00") + "%";  
  28.             }  
  29. }  

补充说明:

①GridView的ShowFooter="true"

②颜色:<HeaderStyle Font-Bold="True" ForeColor="Black" HorizontalAlign="Center" />
                <FooterStyle Font-Bold="true" ForeColor="Black" HorizontalAlign="Center" />

③GridView的OnRowDataBound="_gvGuest_RowDataBound"

0 0
原创粉丝点击