如何在gridview中对不同列进行求和

问题描述:

hi


我有一个组合框,有三种不同类型的项目。当我点击添加按钮然后第一个项目添加gridview然后第二个等等..现在我想要不同类型列的总和并在三个不同的文本框中显示输出。



喜欢



踏板车摩托车骑行

10 22 11

22 33 22





我使用的是此代码,但没有显示明显的价​​值。



hi
I have a combobox which have three different types of item. when I click on the add button then first item add in gridview then second and so on.. Now I want to sum of different types column and show output in three different textboxes.

like

scooter motorcycle cycle
10 22 11
22 33 22


I am using this code but not shows distinct value.

TotalGrossGd = Convert.ToDouble(objDT.Compute("SUM(txtWeight)", ""));
TotalGrossSl = Convert.ToDouble(objDT.Compute("SUM(txtWeight)", ""));
TotalGrossAmount = Convert.ToDouble(objDT.Compute("SUM(txtTotalL)", ""));

txtGrossGd.Text = TotalGrossGd.ToString();
txtGrossSl.Text = TotalGrossSl.ToString();
txtTotalAmount.Text = TotalGrossAmount.ToString();

理想情况是在查询中执行此操作将它显示在网格中。
The ideal scenario would be to do this in the query and display it in the grid.


如果要对特定记录求和并设置数据源,则可以使用datatable的compute函数,或者如果不通过数据源loop设置datagridview并在变量中添加值。
if you want to sum a particular record and setting datasource then you can use the "compute" function of datatable or if not setting through data source "loop" through the datagridview and add the value in a variable.