Jump to content

ASP.NET Shopping Cart

- - - - -

  • Please log in to reply
3 replies to this topic

#1
kthomson

kthomson

    Newbie

  • Members
  • Pip
  • 2 posts
Hi, I need to create a very simple shopping cart in ASP, I have a page with a list of products on using a grid view I want to be able for the user to add a product to a basket, I've managed to use a session variable to do this however i am only able to add one product at a time, when i select to add a new one it just replaces it.

How can I change it so it can have multiple products, also should it be in a separate class?

#2
Roger

Roger

    If nothing goes right, go left.

  • Administrators
  • 717 posts
  • Programming Language:C, PHP
  • Learning:Python
Hi kthomson,

You'll probably have to post some code and output in order for people to help out.
Check out our update Guidelines/FAQ. When posting code, remember to use code tags - Posted Image.

#3
kthomson

kthomson

    Newbie

  • Members
  • Pip
  • 2 posts
Hi, I have this so far:

Default main page:

This is for the select button on the GridView, so when the user clicks select is adds it to the session variable.


 protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

        {     

            Session.Add("bookID", GridView1.SelectedDataKey["BookID"].ToString());

            Response.Redirect("Basket.aspx");

        }


Basket Page: Take the session variable and outputs another grid view based on the BookID, using the SQLStatement below:


 protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

        {     

            Session.Add("bookID", GridView1.SelectedDataKey["BookID"].ToString());

            Response.Redirect("Basket.aspx");

        }

SELECT * FROM [tblBook] WHERE ([BookID] = ?)


Basically I need to so the user can select one item, then the app moves to the basket page then the user can go back to the homepage add another product and then it adds that as well as the previous product to the basket and both will be shown.

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,083 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Can't you use an ArrayList and put that in the session?
If you want to add it you first get the ArrayList out of the session, add to the list, put back in the session.
ArrayList products = (ArrayList) Session["products"];
products.add(newProduct);
Session["products"] = products;

Then you can put multiple things in it, and get multiple out too.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users