We help IT Professionals succeed at work.

Shopping Cart(Session and Arraylist)

123456789y
123456789y asked
on
950 Views
Last Modified: 2013-11-26
My project is in asp.net and sqlserver. Purpose of this site is online shoping for books
Process flow is: User can see 5 books on a page , there is a link called more info
When user selects more info, he gets the detailed description of the book with a choice of Add to Cart and buy it.
I am facing a problem in Add to Cart

'Here is my code for More info.
'Description: When user select LinkButton1 i.e. Add To Cart, then book id is stored in session("BookIDs") 'and page is redirected to add_to_cart.aspx page


Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
On Error GoTo err
Session("BookIDs") = Request.QueryString("bookid")
err: If Session("BookIDs") = 0 Then
Else
Response.Redirect("add_to_cart.aspx?bookid= " & Session("BookIDs") & "")
End If
End Sub

Following is the code for Add_to_cart on Page Load
page_load
bookid=session("BookIDs")
Dim myArrList As ArrayList = New ArrayList
myArrList.Add(bookid)
Session("MyArrayList") = myArrList
Dim bookids As New ArrayList
myNewArrList = CType(Session("MyArrayList"), ArrayList)
If myNewArrList Is Nothing Then
bookids = New System.Collections.ArrayList
End If
If Not myNewArrList Is Nothing Then
bookids.Add(bookid)
End If
For c = 0 To bookids.Count - 1
bookids.Add(bookids.Item(c))
Next
For d = 0 To bookids.Count - 1
If d = bookids.Count - 1 Then
myvalue += "'" & bookids(d).ToString & "'"
Else
myvalue += "'" & bookids(d).ToString & "'" & ","
End If
Next

'---Grid Fill
strSQL = "SELECT book_id, [name], author_name, book_size, price from tbl_bookdetails " 
strSQL = strSQL & " WHERE book_id in (" & myvalue.Trim & ") " 
adp = New SqlDataAdapter(strSQL, conn)
ds = New DataSet
adp.Fill(ds)
grdcart.DataSource = ds
grdcart.DataBind()

Problem is i am not able to store multiple of data, i see one one records at a time.
Even when i go to view cart list, i can see only the details which is requested last, but my requirement is to view all the data which is selected to add in cart list until the browser is closed.

Kindly Suggest.
Its urgent

Thanx in advance


Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank So Much
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.