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

35 篇文章 0 订阅

先上图片,看看是不是你需要的?大笑


关键代码:

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"

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值