0

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 ?

5
Contributors
6
Replies
8
Views
8 Years
Discussion Span
Last Post by __avd
0

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

0

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

0

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;
0

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.

0

Write following code:

if(Session["shopingCart"]!=null) {
  GridView1.DataSource=(List<string>)Session["shopingCart"];
  GridView1.DataBind();
 }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.