如何用C#语言总结网格视图 [英] How to sum a grid view in C# language
本文介绍了如何用C#语言总结网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做网格视图数量列的总和.
如何对网格的特定列求和并将其显示在gridview的最后?
I want to make sum of grid view amount column.
How to sum of a particular column of the grid and display it at the last of gridview??
推荐答案
将GridView绑定到数据源控件时,GridView通过枚举DataSource并一次构建一行来组成.由于每一个GridView行都是数据绑定的,因此将触发GridView的RowDataBound事件.这为页面开发人员提供了以行级粒度进入GridView创建过程的机会.
When the GridView is bound to a data source control, the GridView is composed by enumerating the DataSource and building one row at a time. As each GridView row is databound, the GridView''s RowDataBound event is fired. This provides page developers an opportunity to tap into the GridView creation process at row-level granularity.
int quantityTotal = 0;
void detailsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
quantityTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, _
"Quantity"));
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[0].Text = "Totals:";
e.Row.Cells[1].Text = quantityTotal.ToString("d");
e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Right;
e.Row.Font.Bold = true;
}
}
使用GridView_RowdataBound事件
看到这个
在GridView页脚中显示特定列的总和.
use GridView_RowdataBound event
See this
display sum of particular column in GridView Footer.
这篇关于如何用C#语言总结网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文