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?
3 replies to this topic
#1
Posted 27 November 2010 - 09:56 AM
|
|
|
#2
Posted 27 November 2010 - 10:33 AM
Hi kthomson,
You'll probably have to post some code and output in order for people to help out.
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 -
.
.
#3
Posted 27 November 2010 - 11:20 AM
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.
Basket Page: Take the session variable and outputs another grid view based on the BookID, using the SQLStatement below:
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.
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
Posted 02 December 2010 - 12:52 PM
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.
Then you can put multiple things in it, and get multiple out too.
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


Sign In
Create Account

Back to top









