c# shopping cart module

I have the code attached. It is my shopping cart (1 page) that I tried to get my small project done.
I would like to add Checkout button.

When it is clicked, it will do the following:

1. Add all of the selected products (qty, productname, description) into a database table (sql server). The table structure is exact same as datatable.

2. Email to someone with the selected data.

<%@ Page debug=true Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<title>Shopping Cart</title>
<script runat="server">
Dim objDT As System.Data.DataTable 
Dim objDR As System.Data.DataRow

Private Sub Page_Load(s As Object, e As EventArgs)
     If Not IsPostBack Then
     End If
End Sub

    Function makeCart()
        objDT = New System.Data.DataTable("Cart")
        objDT.Columns.Add("ID", GetType(Integer))
        objDT.Columns("ID").AutoIncrement = True
        objDT.Columns("ID").AutoIncrementSeed = 1

        objDT.Columns.Add("Quantity", GetType(Integer))
        objDT.Columns.Add("Product", GetType(String))
        objDT.Columns.Add("Cost", GetType(Decimal))
        Session("Cart") = objDT
    End Function

Sub AddToCart(s As Object, e As EventArgs)
	objDT = Session("Cart")
	Dim Product = ddlProducts.SelectedItem.Text
	Dim blnMatch As Boolean = False

	For Each objDR In objDT.Rows
		If objDR("Product") = Product Then
			objDR("Quantity") += txtQuantity.Text
			blnMatch = True
			Exit For
		End If

	If Not blnMatch Then
	objDR = objDT.NewRow
	objDR("Quantity") = txtQuantity.Text
	objDR("Product") = ddlProducts.SelectedItem.Text
	objDR("Cost") = Decimal.Parse(ddlProducts.SelectedItem.Value)
	End If
	Session("Cart") = objDT

	dg.DataSource = objDT
	lblTotal.Text = "$" & GetItemTotal()
End Sub

Function GetItemTotal() As Decimal
	Dim intCounter As Integer
	Dim decRunningTotal As Decimal
	For intCounter = 0 To objDT.Rows.Count - 1
		objDR = objDT.Rows(intCounter)
		decRunningTotal += (objDR("Cost") * objDR("Quantity"))
	Return decRunningTotal 
End Function

Sub Delete_Item(s As Object, e As DataGridCommandEventArgs)
     objDT = Session("Cart")
     Session("Cart") = objDT

     dg.DataSource = objDT

     lblTotal.Text = "$" & GetItemTotal()
End Sub


<form runat="server">
<asp:DropDownList id=ddlProducts runat="server">
<asp:ListItem Value="4.99">Socks</asp:ListItem>
<asp:ListItem Value="34.99">Pants</asp:ListItem>
<asp:ListItem Value="14.99">Shirt</asp:ListItem>
<asp:ListItem Value="12.99">Hat</asp:ListItem>
<asp:textbox id="txtQuantity" runat="server" /><br><br>
<asp:Button id=btnAdd runat="server" Text="Add To Cart" onClick="AddToCart" /><br><br>
<asp:DataGrid id=dg runat="server" ondeletecommand="Delete_Item">
<asp:buttoncolumn buttontype="LinkButton" commandname="Delete" text="Remove Item" />
<asp:Label id=lblTotal runat="server" /><br /> 

Open in new window

Who is Participating?
Amandeep Singh BhullarConnect With a Mentor Commented:
Since this is your Home work, so you should do it your self.

I have some suggestions for you:
1. Change the Database table structure. Added the UserID to it, to identify who ordered the products
2. To insert the DataTable into DB, loop throug it and insert data
3. Create a HTML structure and mail it to user. Check:
Webboy2008Author Commented:
I never said this is my home work? Are u ok?
Amandeep Singh BhullarCommented:
Have you tried my suggestions
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.