Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET eCommerce
Hi All,
 
This is the first time i have ever posted in a forum.
I have been working on an eCommerce website for an assignment for quite a while now and cant work out how to calculate
total price = quantity * price
and then a grand total for all the products in the cart
 
i am using list view and have looked at many different codes on google but cant seem to get mine working.
 
This is what i have so far.
 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Cart = GetCart()
        If Not IsPostBack Then
            Me.DisplayCart()
        End If
    End Sub
 
    Private Function GetCart() As SortedList
        If Session("Cart") Is Nothing Then
            Session.Add("Cart", New SortedList)
        End If
        Return CType(Session("Cart"), SortedList)
    End Function
 
    Private Sub DisplayCart()
        lstCart.Items.Clear()
        Dim CartItem As CartItem
        Dim CartEntry As DictionaryEntry
        For Each CartEntry In Cart
            CartItem = CType(CartEntry.Value, CartItem)
            lstCart.Items.Add(CartItem.Display)
        Next
 
    End Sub
 

 
    Protected Sub BtnDlt_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnDlt.Click
        If lstCart.SelectedIndex > -1 And Cart.Count > 0 Then
            Cart.RemoveAt(lstCart.SelectedIndex)
            Me.DisplayCart()
        End If
    End Sub
 
 Dim myTotal As Decimal         'total cost
    Dim myTotalItems As Decimal    'total items in cart
    Dim intCount As Integer         'counter for items in cart

Sub Calculate()
        For intCount As Integer = 0 To lstCart.Items.Count - 1
            myTotal += CDec(lstCart.Items(intCount).Text)
        Next intCount
 
lblTotal.Text = lstCart.Items.Count
 

any help would be great, if i have forgotten to add a piece of code please let me know!
 
thanks
Posted 17-Nov-12 20:04pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 8,149
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 18 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100