考虑唯一ID /日期的gridview列的总和 [英] Sum of gridview column considering unique ID/date
本文介绍了考虑唯一ID /日期的gridview列的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好。是否可以在gridview中总结一列但是只得到唯一日期列的值
说,我有这些值:
Hi. Is it possible to sum up a column in gridview BUT only getting value of unique Date column
Say, I have these values:
____________________
| Date | Value |
| 03/01/16 | 12 |
| 03/02/16 | 6 |
| 03/02/16 | 6 |
| 03/03/16 | 10 |
总计应为12 + 6 + 10 = 28
03/02/16不会被总结,但只会在数据重复后得到一个值。
问候
我尝试了什么:
我尝试使用gridview OnRowDataBound,但总结了所有。
Total should be 12 +6+10 = 28
03/02/16 will not be summed up but will only get the value of one since the data repeats.
Regards
What I have tried:
I tried using gridview OnRowDataBound but it sums up all.
public Decimal TotalValue=0;
protected void gvLevel3OT_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TotalValue+= Convert.ToDecimal(e.Row.Cells[5].Text.ToString());
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[3].Text = "Total";
e.Row.Cells[5].Text = TotalValue.ToString("F");
}
}
推荐答案
在添加值之前,将单元格中的日期与日期进行比较其他行,当前行除外。你可以通过简单的循环或linq来完成。如果找到,请不要添加。
Before adding value, compare the date in the cell with dates other rows, except current row. You can do by a simple loop or linq. If found, don't add.
这篇关于考虑唯一ID /日期的gridview列的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文