473,401 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

calculating total price from gridview values

Good afternoon... I have searched for a solution, but yet to have success... I basically have a fictional shopping cart that contains a column for price. In the footer of the gridview, i need to show the total price of the 'ProductPrice' column. I need the total price to update everytime records are deleted... Is this possible? Currently my total price is stuck at '0' and does not change.

Here is the code for the gridview:

Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
  2.                                         BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" 
  3.                                         CellPadding="4" CellSpacing="2" DataKeyNames="SessionID" 
  4.                                         DataSourceID="AccessDataSource1" OnRowDataBound="GridView2_RowDataBound"
  5.                                         EmptyDataText="There are currently no items in your basket." Font-Bold="True" 
  6.                                         Font-Names="Cambria" Font-Size="Medium" ForeColor="Black" ShowFooter="True" 
  7.                                         style="font-family: Cambria; font-size: medium">
  8.                                         <Columns>
  9.                                             <asp:CommandField ButtonType="Image" DeleteImageUrl="~/Images/x.jpg" 
  10.                                                 DeleteText="Remove" ShowDeleteButton="True" />
  11.                                             <asp:BoundField DataField="SessionID" HeaderText="SessionID" ReadOnly="True" 
  12.                                                 SortExpression="SessionID" Visible="False" />
  13.                                             <asp:BoundField DataField="ProductID" HeaderText="ProductID" 
  14.                                                 SortExpression="ProductID" />
  15.                                             <asp:BoundField DataField="ProductName" HeaderText="ProductName" 
  16.                                                 SortExpression="ProductName" />
  17.                                             <asp:BoundField DataField="ProductPrice" HeaderText="ProductPrice" 
  18.                                                 SortExpression="ProductPrice" />
  19.                                         </Columns>
  20.                                         <FooterStyle BackColor="#CCCCCC" />
  21.                                         <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
  22.                                         <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
  23.                                         <RowStyle BackColor="White" />
  24.                                         <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
  25.                                         <SortedAscendingCellStyle BackColor="#F1F1F1" />
  26.                                         <SortedAscendingHeaderStyle BackColor="Gray" />
  27.                                         <SortedDescendingCellStyle BackColor="#CAC9C9" />
  28.                                         <SortedDescendingHeaderStyle BackColor="#383838" />
  29.                                     </asp:GridView>
  30.                                     <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
  31.                                         DataFile="~/Db1.accdb" 
  32.                                         DeleteCommand="DELETE * FROM [Basket] WHERE [SessionID] = ?" 
  33.                                         SelectCommand="SELECT * FROM [Basket]">
  34.                                         <DeleteParameters>
  35.                                             <asp:Parameter Name="SessionID" Type="Int32" />
  36.                                         </DeleteParameters>
  37.                                     </asp:AccessDataSource>
... And here is the code for the rowdatabound for the gridview:

Expand|Select|Wrap|Line Numbers
  1. Sub GridView2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound
  2.  
  3.  
  4.         Dim priceTotal As Decimal = 0
  5.  
  6.  
  7.  
  8.         If e.Row.RowType = DataControlRowType.DataRow Then
  9.             ' add the UnitPrice and QuantityTotal to the running total variables
  10.             priceTotal = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ProductPrice"))
  11.  
  12.         ElseIf e.Row.RowType = DataControlRowType.Footer Then
  13.             e.Row.Cells(3).Text = "Totals:"
  14.  
  15.             e.Row.Cells(4).Text = priceTotal.ToString("c")
  16.  
  17.  
  18.             e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Right
  19.             e.Row.Cells(2).HorizontalAlign = HorizontalAlign.Right
  20.             e.Row.Font.Bold = True
  21.         End If
  22.  
  23.     End Sub
  24.  
Any help would be greatly appreciated. Thank you!
Apr 4 '13 #1
0 1061

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: John | last post by:
hey all..... alright, I am frusterated to the point of throwing my machine out the window (this board went down, trying to find stuff on google, this has been a nightmare) so I hope you guys can...
5
by: RC | last post by:
I have a form with three text boxes on it. I want the third text box to show the total of the values in the other two text boxes. The first box is named: BoxOne and I type the number 2 into it...
4
by: rbronco28 | last post by:
I am pretty new at doing web development. I can make simple pages, but recently received a request from a small limo business I do web development for. We are currently working on a reservation...
0
parshupooja
by: parshupooja | last post by:
Hi All, I have gridview with following columns date--morningin--morningout--afetrnoonin--afetrnoonout I want to create another 6th coulmn which shd display total...
9
parshupooja
by: parshupooja | last post by:
Hi I am using asp.net C# and javascript. I have a gridview with 5 columns and 14 row column1--column2--column3--column4--column5 Column1 to column4 is textboxes wheresa column5 is label I am...
3
by: tshad | last post by:
I am building a GridView that is displaying some money values in 3 columns. I want to put the totals of each column in a label field (one for each column) in the footer. I was trying to figure...
0
by: hiranmaie | last post by:
Hi, I have a gridview with more than 10 rows of data. I want to export these gridview values into an excel sheet along with the header names of excel sheet. I am not using a database here. I...
4
by: sumit kale | last post by:
Hi, Can somebody help me resolve my problem ? I am getting error when calculating total using unbound textfiled in subform. I have a main form called purchase_register_master and a subform...
3
by: HTIDIRECT | last post by:
I am currently creating a form that requires me to have multiple comboboxes which have various options with different values. What I am having a problem with is finding a javascript snippet that...
0
by: tnynyn | last post by:
I have created a form with two datetimepicker showing only hours (start and end times). I have timespan calculating the total hours, but when it goes to the next day, it adds 24 hours. For example,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.