如何在datagridview中添加特定列的值 [英] How to add up value of a particular column in datagridview

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

问题描述

你好朋友
我有一个datagridview从数据库检索信息.我的数据库有一个表,该表有一个称为收入的列,现在我想要的是一种在每天结束时对收入列的值进行求和的方法,以获取当天的总收入.请提前对此表示感谢.

Hi friends
i have a datagridview that retreive information from a db. My db has a table that has a column called income, now what i want is a way to sum up the value of the income column at the end of everyday to get the total income for that day. Please i need help on this thanks in advance

推荐答案

我不确定这是否是正确的答案,您可以使用两个控件来实现所需的功能. br/>
使用具有唯一天数的Repeater,然后将GridView放入该Repeater.

使用GridView的页脚显示收入总额"列.


I am not sure if this is the right answer, tho you can use two controls to achieve what you want.

Use a Repeater which gets the unique days and then put the GridView inside that repeater.

Use the footer of the GridView to show the Sum of Income column.


<asp:Repeater> <!-- Get unique days -->
 <ItemTemplate>
  <asp:GridView> <!-- Bind the data based on the day -->
 </ItemTemplate>
</asp:Repeater>


put a textbox in the footer control then find the textbox control using

textbox txtSum= gridview1.FooterRow.FindControl("txtTotal") as TextBox

Then bind the total value to txtSum like how you will bind data to grid

txtSum= "select sum(income) from incometable" 


这篇关于如何在datagridview中添加特定列的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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