Click here to Skip to main content
16,016,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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...?
Posted

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)

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

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

hope this helps.
 
Share this answer
 
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
 
Share this answer
 
Comments
gani7787 21-Dec-11 9:28am    
Thanks Varun.

But, this should happen when i press every textbox in gridview, it should automatically change in the total textbox.

How it is possible...?
Varun Sareen 27-Dec-11 1:37am    
You should have to have an event associated with the text change.

Thanks
ledtech3 21-Dec-11 12:35pm    
Just clicking on a box wouldn't do anything unless there is a click event tied to the box.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900