Home > ASP.Net > How to Display Sum Total in the Footer of the GridView Control

How to Display Sum Total in the Footer of the GridView Control


Hi

try this example:

<asp:GridView ID="GridView1"
  ShowFooter="true" DataKeyNames="ProductId"
  AutoGenerateColumns="false" runat="server"
  DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="Productid" HeaderText="Product Id" />
<asp:BoundField DataField="ProductName" FooterText="Total" HeaderText="Product Name" />
<asp:TemplateField HeaderText="Unit Price" FooterStyle-Font-Bold="True">
<ItemTemplate>
  <%# GetUnitPrice(decimal.Parse(Eval("UnitPrice").ToString())).ToString("N2") %>
</ItemTemplate>
<FooterTemplate>
  <%# GetTotal().ToString("N2") %>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings: DummyDB %>"
SelectCommand="Select * from Products">
</asp:SqlDataSource>

in code behind:

decimal TotalUnitPrice;
decimal GetUnitPrice(decimal Price)
{ 
  TotalUnitPrice += Price;
  return Price;
}
decimal GetTotal()
{
  return TotalUnitPrice;
}

Good Luck

Advertisements
Categories: ASP.Net
  1. July 18, 2013 at 1:45 pm

    Hi there to every single one, it’s truly a good for me to pay a quick visit this website, it contains precious Information.

  2. March 16, 2014 at 11:37 pm

    Spot on with this write-up, I honestly believe that this website needs far more attention.
    I’ll probably be back again to read through more, thanks for the
    advice!

  3. April 1, 2014 at 8:24 pm

    whoah this blog is great i like reading your articles.
    Stay up the good work! You understand, many people are searching around for this information, you could help them greatly.

  4. April 27, 2014 at 2:15 pm

    I really like your blog.. very nice colors & theme.
    Did you create this website yourself or did you hire
    someone to do it for you? Plz reply as I’m looking to create my own blog
    and would like to know where u got this from. appreciate it

    • yasserzaid
      April 30, 2014 at 7:38 pm

      Thank you i hope my blog helps you .. for theme this is provided by wordpress as template

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: