如何添加或计算gridview文本框值? [英] How to add or count gridview text box values.?

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

问题描述



我有gridview,其中一列包含动态文本框.

我想计算(添加)所有Gridview文本框值,并希望存储在文本框的一个单独的外部网格中.

Hi,

I have gridview and one column contains dynamic textbox.

I want to calculate(Add) all the Gridview textbox values and want to store in one seperate outside grid of the text box..

How to calculate...?

推荐答案

亲爱的加尼,

您正在动态添加文本框的意思是,如果是这种情况,则在网格的行数据绑定的同时进行绑定:-

1)一旦网格行数据绑定完成,您就可以在网格上进行一个foreach循环,并将所有文本框的值保存到一个整数(或十进制)变量中,方法如下:-

整数sumOfTxtVal;
sumOfTxtVal = sumOfTxtVal + Convert.toInt32(txtValues.Text);

2)或者在发生行数据绑定并将文本框动态绑定到网格中时,一旦将特定文本框逐行绑定,则应用上面的公式.

如果这对您有帮助,请标记为您的答案

谢谢

Varun Sareen
Dear Gani,

You are adding the textboxe''s dynamically means while row databound of grid you are bounding if that is the case then:-

1) once the grid row databound is completed then you can make a foreach loop on the grid and save the value of all textboxes into a integer (or decimal) variable by:-

integer sumOfTxtVal;
sumOfTxtVal=sumOfTxtVal+ Convert.toInt32(txtValues.Text);

2) Or while the row databound is happening and binding textboxes into the grid dynamically then once it the particular textbox is binded row wise then apply the above formulae.

If this helps you out then please mark this as your answer

Thanks

Varun Sareen


Varun Sareen在第二个答案中指出,更简单的方法是在获得数字时将它们相加.像(我的在VB中)之类的东西

As Varun Sareen Sugested in the second answer the easier way would be to add the numbers as they are gotten. Something like (mine is in VB)

Dim ItemToAdd As Integer
  For Each DataItem In SomeCollection 'SomeCollection = pulling data from
          ItemToAdd = ItemToAdd + DataItem
          Total.text = ItemToAdd.ToString
      Next


如果您需要的话,也许Varun Sareen可以向您显示"C"版本

希望对您有所帮助.


Perhaps Varun Sareen Can Show you the "C" version if that is what you need

hope this helps.


这篇关于如何添加或计算gridview文本框值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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