按数据表分组 [英] Group by in datatable
问题描述
HI Friends
我想将gridview导出为excel.我正在将数据从SQL检索到datatable,然后绑定到gridview,我想要的是我想根据货币将dt中的行分组,并找到这些行的总值.
EG
< u>名称货币金额</u>
INR 100
B AUD 25
INR 5
D EUR 30
上面的是datable,我想要dt这样的
INR 100
INR 5
105
-----------------------------
B AUD 25
25
-----------------------------
D EUR 30
30
-----------------------------
就像他想要的那样,必须将其导出到excel
可以帮助您解决方案
您可以通过自定义在Gridview中进行操作,请查看以下CP文章
组GridView数据 [ GroupingView [组总计,网格视图中的总计 [ ^ ]
GridView:使用两行代码创建组和摘要 [在C#中的Datatable上应用分组依据子句 [ ^ ]
一种可能是在代码中为每个组添加总行,并使用 ^ ]方法来计算每个组的SUM.
HI Friends
I want to export gridview to excel. I''m retrieving data from SQL to datatable , thn binding to gridview , What i want is I want to group the rows in dt based on currency and find the total value of that rows.
EG
<u>Name Currency Amount</u>
A INR 100
B AUD 25
C INR 5
D EUR 30
the above one is the datable and i want the dt as this
A INR 100
C INR 5
105
-----------------------------
B AUD 25
25
-----------------------------
D EUR 30
30
-----------------------------
like this iwant he dt and have to export this to excel
ANy help wil b appreciated
You may do that in your Gridview by customization, check these CP articles
Group GridView Data[^]
GroupingView[^]
Also check these
Group Total, Grand Total in Grid View[^]
GridView: Creating groups and summaries with 2 lines of code[^]
Apply group by clause on Datatable in C#[^]
One possibility is to add the total rows in your code for each group and use Compute[^] method to calculate the SUM for each group.
这篇关于按数据表分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!