Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

ASP.NET Shopping Cart

asp.net

  • Please log in to reply
3 replies to this topic

#1 kthomson

kthomson

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 27 November 2010 - 09:56 AM

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?
  • 0

#2 Roger

Roger

    Skadoosh!

  • Administrator
  • 1222 posts
  • Programming Language:C, PHP
  • Learning:Others

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.
  • 0

New around here? Click here to register and start participating in under a minute?

Or do a quick search and you may find the answer you're looking for.


#3 kthomson

kthomson

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

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.


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.
  • 0

#4 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

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.
ArrayList products = (ArrayList) Session["products"];
products.add(newProduct);
Session["products"] = products;

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





Also tagged with one or more of these keywords: asp.net

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download