Calculate running total in a grid view and display

Madhu.b.rokkam
Posted by in ASP.NET category on for Advance level | Points: 250 | Views : 20386 red flag

This one is really very useful whenever we have a need to calculate running totals in the grid either row wise or in column wise.


 Download source code for Calculate running total in a grid view and display

Introduction

As per one of our DNF friend’s need I thought of writing this article. This one is really very useful whenever we have a need to calculate running totals in the grid either row wise or in column wise.
So let’s start to build this application.

Step1- Open Visual studio and add new website project.


Step2 – Rightclick on the project -> add new item -> Select xml file -> Name it as Data.xml

Step3- Create a sample data for the grid view. I have created my sample in an xml file. You can also have this in the SQL Server also.

The xml file has data for three employee salary and bonus details and we will calculate the gross salary and the total gross salary dynamically.

Step4- Add a new Gridview to the aspx page and add three bound fields and three template fields. And design as shown below

The Gross salary and the total gross salary we will calculate at runtime dynamically.

Step-5  The ASPX source will have the gridview content as below


Step-6 Load the data from xml to grid view on page load

Step-7 On RowDataBound of the grid view we need to register client side array declaration and setting the javascript calculate function to the textboxes for calculating dynamically.

Step -8 Now we have to add our logic into javascript function

Thats it... Build and run your application. You do any change to the salary field or bonus field the gross salary and the total gross salary gets calculated dynamically.

Conclusion

Hope this artical will help all to understand the how easily we can have all our calculations done with in the grid view so easily with very less code.  

Page copy protected against web site content infringement by Copyscape

About the Author

Madhu.b.rokkam
Full Name: Madhu Rokkam
Member Level: Bronze
Member Status: Member,MVP
Member Since: 1/13/2011 3:13:20 PM
Country: India
Thanks and Regards Madhu
http://www.dotnetfunda.com

Login to vote for this post.

Comments or Responses

Posted by: Tripati_tutu on: 2/17/2011 | Points: 25
Nice article...
Posted by: Madhu.b.rokkam on: 2/17/2011 | Points: 25
Thanks Tripati ..
Posted by: Gopal_nivas on: 2/17/2011 | Points: 25
nice article madhu..

regards
gopal.s

Login to post response

Comment using Facebook(Author doesn't get notification)