汇总DataGrid [英] Summing DataGrid
本文介绍了汇总DataGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我如何遍历具有两列的数据网格,其中列A是产品的下拉列表,列B是文本框.假设数据网格有十行,其中四行具有产品ID = A1的下拉列表,三行具有Product ID = A2的下拉列表,两行具有Product ID = A3的下拉列表,而另一行具有Product ID = A4的下拉列表.我希望能够通过对每组产品ID的文本框值求和来循环.
Hi Guys,
How do i loop through a data grid with say two columns where Column A is a pulldown of products and Column B is a Text box. let say the data grid has ten rows, with four of the rows have pulldown with Product ID=A1, three with Product ID=A2,two with Product ID=A3 and one with Product ID=A4. I would like to be able to loop through summing the the text box values for each group of Product ID.
推荐答案
您需要使用数据网格的RowBound事件.
使用FindControl方法获取数据网格内文本框的引用,并将其值存储在viewstate变量中(求和).
例如:
ViewState ["sum"] = Convert.ToInt32(ViewState ["sum"])+数字;
在任意位置显示viewstate变量,它将显示总和.
You need to use the RowBound event of the data grid.
Using FindControl method get reference of the text box inside data grid and store its value in a viewstate variable(summing it).
example:
ViewState["sum"] = Convert.ToInt32(ViewState["sum"]) + number;
Display the viewstate variable wherever you want and it will show the total sum.
^ ]线程可能会有所帮助.它讨论了许多方法.
This[^] thread might help. It discusses a number of approaches.
这篇关于汇总DataGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文