如何在datagridview c#中的两行值之和 [英] How to sum of two rows values inside the datagridview c#

查看:127
本文介绍了如何在datagridview c#中的两行值之和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果两个行的id相同并且在DataGrid中创建一行而不是两行,如何在DataGridView中合并两行值?







How to sum of two rows values inside the DataGridView, if the id of the both rows same and create one rows instead of two rows in the DataGrid?



Like the following example:

id          quantity       Bonus        price           total
 
01             25           10           123            4305
 
01             5             10          123            1845
 

I want to sum of the above two rows like this in the DataGrid.


id           quantity        Bonus         price          total
 
01              30            20             246          6150





如果我循环它然后在datagridview中复制值插入。



if i take loop on it then duplicate value insert in the datagridview.

推荐答案

如果您的数据来自SQL数据库,请使用如下查询:

If your data comes from SQL database, use query like this:
SELECT id, SUM(quantity) AS quantity, SUM(Bonus) AS Bonus, SUM(price) AS price, SUM(total) AS total
FROM YourTableName
GROUP BY id


看到这个.. :)



页脚上的GridView摘要 [ ^ ]



display-sum-column-values-asp-net-gridview -footer-using-jquery [ ^ ]



在ASP.NET C#VB.NET中在Gridview页脚中运行总计 [ ^ ]



显示GridView的页脚总数以及在最后一列中添加列的总和(行虎钳)[ ^ ]



显示GridView的页脚总数 [ ^ ]



在asp.net中的gridview页脚中显示总列数的总和 [ ^ ]



May是不是像你想要的那样,但你可以从中得到... ...)
see this.. :)

GridView summary on Footer[^]

display-sum-column-values-asp-net-gridview-footer-using-jquery[^]

Running Total In Gridview Footer In ASP.NET C# VB.NET[^]

Displaying Total in Footer of GridView and also Add Sum of columns(row vise) in last Column[^]

Displaying Total in Footer of GridView[^]

Display sum of columns total in gridview footer in asp.net[^]

May be it is not same like as you want but you can get idea from it... :)


这篇关于如何在datagridview c#中的两行值之和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆