Here is the scenario:

I have pages that we can add items to "shopping cart",here is the code:

List<string> shopingCart = (List<string>)Session["shopingCart"];
if (shopingCart == null)
    {
            shopingCart = new List<string>();
            Session["shopingCart"] = shopingCart;
    }
    shopingCart.Add(Request.QueryString["ID"]);

I store the ID of each product in Session state(which is unique), then I want to show all selected items with additional information related to them in GRIDVIEW .

How can I handle this ?

Recommended Answers

All 6 Replies

use session....session is hot gal...

she'll do you can anything you want.....

session store anything...or any object...like array, arraylist...etc

try...and let me know if things work out for you...

transfer the session contents to an array and then populate the gridview from array

would you please write the related code.

First Request.QueryString["ID"]) is not stored in Session as you are storing the shopingCart to the Session before adding the ID to that object.

You code should look like

List<string> shopingCart = (List<string>)Session["shopingCart"];
if (shopingCart == null)
{
shopingCart = new List<string>();
}
shopingCart.Add(Request.QueryString["ID"]);
Session["shopingCart"] = shopingCart;

Thank you Ramesh but I debug the previous code and it worked too.

I can also show ID's to the girdview, but my real problem is that I don't know how to retrieve the hole record from database according to my primary key(ID) and show in gridview.

By the way I want to make shopping Cart page.

Write following code:

if(Session["shopingCart"]!=null) {
  GridView1.DataSource=(List<string>)Session["shopingCart"];
  GridView1.DataBind();
 }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.