Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.


VB
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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900