http://www.sitepoint.com/article/net-shopping-cart-datatables/2
I've been playing around this for almost 1 day and half. I can get it working, on its current page.
But here is my problem when i go ahead and add a link button to link to another page and that page is empty except it contains a link button to link back to my shopping cart. My shopping cart disappears.
Heres the code:
1Dim objDTAs System.Data.DataTable 2Dim objDRAs System.Data.DataRow3 4Private Sub Page_Load(sAs Object, eAs EventArgs)5If Not IsPostBackThen6 makeCart()7End If8End Sub9 10Function makeCart()11 objDT =New System.Data.DataTable("Cart")12 objDT.Columns.Add("ID",GetType(Integer))13 objDT.Columns("ID").AutoIncrement =True14 objDT.Columns("ID").AutoIncrementSeed = 115 16 objDT.Columns.Add("Quantity",GetType(Integer))17 objDT.Columns.Add("Product",GetType(String))18 objDT.Columns.Add("Cost",GetType(Decimal))19 20 Session("Cart") = objDT21End Function22 23Sub AddToCart(sAs Object, eAs EventArgs)24 objDT = Session("Cart")25 26 objDR = objDT.NewRow27 objDR("Quantity") = txtQuantity.Text28 objDR("Product") = ddlProducts.SelectedItem.Text29 objDR("Cost") =Decimal.Parse(ddlProducts.SelectedItem.Value)30 objDT.Rows.Add(objDR)31 32 Session("Cart") = objDT33 34 dg.DataSource = objDT35 dg.DataBind()36 37 38End Sub39 40Any suggestions on how to fix/why this is happening? I just started asp.net and so yea running into this problem has stumped me.
Hi,
Well you are only binding the DataGrid when you add to the cart??
You need to bind it when you are making the cart
dg.DataSource = Session("Cart")
dg.DataBind()
HTH
j
Thanks.
I tried that with no success
But i've fixed it now and i guess i got the problem wrong. Since the actual problem was the table being recreated.
:D Anyways thanks for the help ^^
0 comments:
Post a Comment