Public Class ShoppingCarts Inherits System.Web.UI.Page Private tblShoppingCart As DataTable = Nothing Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'If (Not String.IsNullOrEmpty(Request.QueryString("ShoppingCookie"))) Then Dim tblShoppingCart As DataTable = New DataTable("CartTable") Dim rwShoppingCart As DataRow If Session("basket") IsNot Nothing Then tblShoppingCart = DirectCast(Session("basket"), DataTable) Else tblShoppingCart = New DataTable() tblShoppingCart.Columns.Add("Prod_ID") tblShoppingCart.Columns.Add("Prod_Name") tblShoppingCart.Columns.Add("Prod_Category") tblShoppingCart.Columns.Add("Prod_Price") tblShoppingCart.Columns.Add("Prod_Quantity") tblShoppingCart.Columns.Add("Prod_Total_Price") End If If Request("DelID") IsNot Nothing Then 'search and remove For i As Integer = 0 To tblShoppingCart.Rows.Count - 1 If tblShoppingCart.Rows(i)(0).ToString() = Request("DelID").ToString() Then tblShoppingCart.Rows.Remove(tblShoppingCart.Rows(i)) End If Next End If If Request("ShoppingCookie") IsNot Nothing Then 'search item in DataTable Dim Found As Boolean = False For i As Integer = 0 To tblShoppingCart.Rows.Count - 1 If tblShoppingCart.Rows(i)(0).ToString() = Request("ShoppingCookie").ToString() Then Found = True UpdateCarts() End If Next If Found = False Then Try Dim SQLCon As New SqlConnection With {.ConnectionString = "Server=MEIYI-PC;Initial Catalog=VBTrading;Integrated Security=True"} SQLCon.Open() Dim cmd As New SqlCommand("SELECT Prod_ID, Prod_Name, Prod_Category, Prod_Price, Prod_Quantity FROM PRODUCT WHERE Prod_ID = " & Replace(Request.QueryString("ShoppingCookie"), "'", "''"), SQLCon) Dim dr As SqlDataReader dr = cmd.ExecuteReader If (dr.Read) Then rwShoppingCart = tblShoppingCart.NewRow rwShoppingCart(0) = dr(0).ToString() rwShoppingCart(1) = dr(1).ToString() rwShoppingCart(2) = dr(2).ToString() rwShoppingCart(3) = dr(3).ToString() rwShoppingCart(4) = dr(4).ToString() tblShoppingCart.Rows.Add(rwShoppingCart) Dim x As Int16 For x = 0 To tblShoppingCart.Rows.Count - 1 rwShoppingCart(5) = rwShoppingCart(3) * rwShoppingCart(4) Next Else Response.Write("Membership Empty") End If SQLCon.Close() Catch ex As Exception Response.Write(ex.Message) End Try ' Next End If End If If IsPostBack = False Then CartRepeater.DataSource = tblShoppingCart CartRepeater.DataBind() End If Session("basket") = tblShoppingCart ' End If End Sub Sub UpdateCarts() Dim x As Int16 Dim txtBox As TextBox Dim txtBox2 As Literal Dim txtBox3 As Literal Try For x = 0 To CartRepeater.Items.Count - 1 txtBox = DirectCast(CartRepeater.Items(x).FindControl("txtQuantity"), TextBox) txtBox2 = DirectCast(CartRepeater.Items(x).FindControl("lblPrice"), Literal) txtBox3 = DirectCast(CartRepeater.Items(x).FindControl("lblTotalPrice"), Literal) txtBox3.Text = txtBox.Text * txtBox2.Text Next Catch End Try End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)