如何计算网格视图上小计下方行中的百分比
本文关键字:方行中 百分比 视图 何计算 计算 网格 | 更新日期: 2023-09-27 18:34:53
我想在我的GridView
上再创建一行,或者它们可以是显示December2014DailySales
和December2013DailySales
小计之间百分比变化的独立单元格。我已经提供了背后的代码。我该怎么做?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace TowelsRusV3
{
public partial class Sales_Comparison : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private decimal December2014DailySales = (decimal)0.0;
private decimal December2013DailySales = (decimal)0.0;
private decimal DailySalesDifference = (decimal)0.0;
private decimal December2014DailyOrderCount = (decimal)0.0;
private decimal December2013DailyOrderCount = (decimal)0.0;
private decimal DailyOrderCountDifference = (decimal)0.0;
protected void salecompgridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
December2014DailySales += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "December2014DailySales"));
December2013DailySales += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "December2013DailySales"));
DailySalesDifference += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "DailySalesDifference"));
December2014DailyOrderCount += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "December2014DailyOrderCount"));
December2013DailyOrderCount += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "December2013DailyOrderCount"));
DailyOrderCountDifference += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "DailyOrderCountDifference"));
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[1].Text = String.Format("{0:c}", December2014DailySales);
e.Row.Cells[3].Text = String.Format("{0:c}", December2013DailySales);
e.Row.Cells[5].Text = String.Format("{0:c}", DailySalesDifference);
e.Row.Cells[2].Text = String.Format("{0:g}", December2014DailyOrderCount);
e.Row.Cells[4].Text = String.Format("{0:g}", December2013DailyOrderCount);
e.Row.Cells[6].Text = String.Format("{0:g}", DailyOrderCountDifference);
}
}
}
}
您可以将该值存储在网格的任何单元格中,如下所示:
salecompgridview.Rows[0].Cells[0].Text = ((December2014DailySales - December2013DailySales) / December2013DailySales * 100).ToString();
只需使用适当的行索引和单元格索引即可。
尝试手动添加一行,并将空单元格设置为 ",将非空单元格设置为预先计算的值。希望对您有所帮助。