How to display sum of particular column in GridView Footer.

The following code sample shows how to display text in GridView Footer.

Stpes:

1) Set GridView ShowFooter property to true;

2) Write the below code in GridView_RowdataBound Event

     
if ( e.Row.RowType == DataControlRowType.DataRow )
sum = sum + Convert.ToInt32 ( e.Row.Cells [ 0 ].Text );
else if ( e.Row.RowType == DataControlRowType.Footer )
e.Row.Cells [ 0 ].Text = sum.ToString ( "c" );


Thats it...


Comments

Author: Alok Kumar Mohanty28 May 2008 Member Level: Silver   Points : 2

Very good and useful code

Author: vasanthiraajan30 May 2008 Member Level: Gold   Points : 2

hi,

thank u very much.

Author: Bachan rawat03 Jun 2008 Member Level: Silver   Points : 2

Hi,
This article is nice.
How to display sum of particular column in GridView Footer if we allow paging , sorting and export btn to export data to excel.

Author: aNiL11 Sep 2008 Member Level: Silver   Points : 0

Nice post.

really helpfull...........

Author: priyaravi13 Feb 2009 Member Level: Silver   Points : 0

hi
thankyou verymuch.its very helpful

Author: Sasikumar18 Feb 2009 Member Level: Gold   Points : 1

Very good and useful code

Compileable Code....

Good One........

Keep It UP..

Author: Nirav Lalan23 Jan 2014 Member Level: Gold   Points : 0

i am not clearing with sum, what it is.?



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: