如何计算Gridview中的总列数? ? [英] How to Calculate Total Column in Gridview ? ?

查看:81
本文介绍了如何计算Gridview中的总列数? ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友!!



我的网络表格上有一个Gridview。最后我用数据库填充它。



我这个Gridview记录将填充Form,这表示它包含Textboxes和Button。

在将文本和数字输入文本框后,当提交按钮点击时,这些Textboxes值将填入gridview ...所以它的插入井。



但现在我需要总金额在底部。



示例Gridview显示

==================== ====

名称项目金额
----- ---- ------
Raju笔记本电脑15000
Varun HandyCam 12000
Teja Iphone 18000
Ranjith PC 22000



现在我们需要自动下面的总金额。



请告诉我,如何在Gridview中做总额。



谢谢。

解决方案

  int  sum =  0 ; 
foreach (DataRow dr in datatable.Rows)
{
sum = sum + Convert.ToInt32(dr [ Amount]);
}





sum变量将包含所有值的总和。使用此'sum'你需要。



chk this out ....


你可以使用 CellValidated [ ^ ]事件并将计算放在那里。



另请参阅以下主题:



本文演示如何在GridView中开发客户端计算,并且计算表达式可在DB端配置:

GridView中数据库驱动的客户端计算 [ ^ ]



使用JavaScript / JQuery:

使用JavaScript / JQuery计算GridView总数 [ ^ ]



如何为gridview列添加客户端计算 [ ^ ]

如何在GridView控件的页脚中显示总和 [ ^ ]



ASP.NET的GridView示例:在页脚中显示摘要数据 [ ^ ]

在GridView的页脚中显示摘要信息 [ ^ ]



查看以下链接中的类似讨论:

在ASP.net C#中计算网格中的总价值 [ ^ ]



希望你能从中得到一些帮助!


你应该使用gridview的FooterRow然后
tabind你可以写这一行



 GridView.FooterRow.Cells [ 2 ]。文本= ds.Tables [ 0 ]。计算(  sum(Amount) )。ToString(); 


Dear Frnds !!

I have a Gridview on my webform. Finally i have filled it with database.

I this Gridview Records will be filled with Form, This forms it contains Textboxes and Button.
and these Textboxes value will be filled in gridview when submit button clicks after entering text and numbers into textbox...so its Inserting Well.

But now i need Total Amount at bottom.

Example Gridview Display
========================

Name        Item         Amount
-----       ----         ------  
Raju       Laptop         15000
Varun      HandyCam       12000
Teja       Iphone         18000
Ranjith     PC            22000 


Now We need Total Amount Automatically below.

Please show me, how to do total amount in Gridview.

Thanks.

解决方案

int sum = 0;
foreach(DataRow dr in datatable.Rows)
{
    sum = sum + Convert.ToInt32(dr["Amount"]);
}



sum variable will contain the total of all the values.Use this 'sum' where ever u need.

chk this out ....


You can use CellValidated[^] event and place your calculations in there.

Also refer following threads:

This article demonstrates how to develop client side calculations in a GridView, and calculation expressions are configurable at the DB side:
Database driven client side calculations in GridView[^]

Using JavaScript/JQuery:
Calculating GridView total using JavaScript/JQuery[^]

How To Add client side calculation for gridview column[^]
How to Display Sum Total in the Footer of the GridView Control[^]

GridView Examples for ASP.NET: Displaying Summary Data in the Footer[^]
Displaying Summary Information in the GridView's Footer[^]

Check similar discussion on following link:
Calculate Total Value In Gridvew In ASP.net C#[^]

Hope you get some needful from it!


You should use FooterRow of gridview then
after databind you can write this line

GridView.FooterRow.Cells[2].Text = ds.Tables[0].Compute("sum(Amount)", "").ToString();


这篇关于如何计算Gridview中的总列数? ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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