• How to display column total in GridView footer in ASP.NET

    by  • May 26, 2013 • Microsoft .NET C# (C-Sharp), Microsoft ASP.NET • 0 Comments

    Those who use GridVeiw to display data in ASP.NET sometimes need to display column total at the end.  I will explain in following code snippet that how easily you can accomplish your requirement.

    I am using NORTHWND sample database for this article. You can download source code at the end of this article.

    First of all use following namespaces to use below code snippet.

    Now see what you need to do in your GridView.

    Here you see I am using two labels in FooterTemplate of TemplateFields. I will use these labels to show total.

    Now let’s see the code in code behind file.

    Here you can see that at the top I have declared two variables for total price and total units. In page load event, I am retrieving data from Products table of NORTHWND database and populating my GridView. In RowDataBound event, I am adding each data row for total price and total units. At the end in footer, I am getting two labels declared in FooterTemplate of GridView TemplateFields and assigning values of total price and total units to them.

    Best WordPress Themes and Plugins with Great Team and Support!

    Avatar of GetCodeSnippet.com


    GetCodeSnippet.com provides you high quality Microsoft .NET development related articles, tutorials and sample code for ASP.NET, C#, VB.NET, AJAX, WCF, WPF, Web Services, Windows Services, SQL Server and other technologies.

    Leave a Reply