Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 18th, 2006, 11:06 AM
Friend of Wrox
Join Date: Oct 2005
Location: , , United Kingdom.
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
Default Calculating Gridview Column Values

Hi All

Is there a way to calculate the values within a Gridview column?

I am displaying a row count and total for a particular column.

Many thanks
  #2 (permalink)  
Old October 18th, 2006, 03:46 PM
Friend of Wrox
Join Date: Oct 2005
Location: , , United Kingdom.
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post

OK, I have found the following sample which works well by placing the total within the footer of the Gridview.

Does anyone know how I could place the total being calculated within a variable so I can use it within other calculations?...

Gridview -
<asp:GridView ID="GridView1"
  ShowFooter="true" DataKeyNames="ProductId"
  AutoGenerateColumns="false" runat="server"
<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">
  <%# GetUnitPrice(decimal.Parse(Eval("UnitPrice").ToString())).ToString("N2") %>
  <%# GetTotal().ToString("N2") %>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:DummyDB %>"
SelectCommand="Select * from Products">
Helper Function -
Dim TotalUnitPrice As Decimal = 0.0
Function GetUnitPrice(ByVal Price As Decimal) As Decimal
  TotalUnitPrice += Price
  Return Price
End Function
Function GetTotal() As Decimal
  Return TotalUnitPrice
End Function

"Curtesy of http://aspalliance.com/782"

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Get GridView Cell Value Based on GridView Column stublair C# 2008 aka C# 3.0 0 September 4th, 2008 08:30 AM
Calculating input values with arrays Ray Z Javascript 0 July 19th, 2006 09:20 PM
calculating values aceconcepts PHP How-To 0 February 16th, 2006 09:01 AM
Calculating Grouped Report Values SteveH Access 1 October 15th, 2005 03:00 PM
Calculating "Sum" of Numeric values in Varchar fld itHighway Classic ASP Basics 6 December 29th, 2004 07:41 PM

All times are GMT -4. The time now is 11:22 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.