添加和删​​除会话中存储的购物车项目

时间:2019-10-12 23:05:42

标签: asp.net vb.net

对于一项作业,我必须创建一个购物车,我选择使用会话在添加购物车项目时保留它们,但是如何允许用户删除项目或更新数量?

这是用户单击“添加到购物车”后,购物车页面的代码,将产品数据从请求数据中提取出来,插入对象中,然后添加到会话中。然后将会话的内容显示在gridview中,但这似乎并没有为我管理内容(即添加删除按钮,数量输入)

Partial Class ShoppingCart
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        'Create a new product from the request data'
        Dim ProductToAdd As New Product
        ProductToAdd.productPrice = Request.QueryString("Price")
        ProductToAdd.productTitle = Request.QueryString("Title")
        ProductToAdd.productQuantity = 1

        'Check if the session exists'
        If Session("Cart") Is Nothing Then
            Session("Cart") = New List(Of Product)
        End If

        'Add the product object to the session'
        Session("Cart").Add(ProductToAdd)

        'Update the UI'
        With Session("Cart")
            GridView1.DataSource = Session("Cart")
        End With

        GridView1.DataBind()

    End Sub
End Class

要添加的项目

enter image description here

购物车页面

enter image description here

0 个答案:

没有答案