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
Dim myTotalItems As Decimal
Dim intCount As Integer
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