How to create store gridvalues in session and retrieve each session separately

Using LinQ ,I have a browse page where customer can select rows from a grid , the selected rows should be displayed in a shopping cart grid. Since, I was unable to do a grid to grid transfer I created a database table CART where I added each selected row to it using textboxes. Now, I call in values from CART table and display in shopping cart grid. How can I create sessions for all attributes(columns) of all items in the cart? I am not sure how to use array list for sessions and then extracting each session separately…

   <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    DataKeyNames="CartID" DataSourceID="SqlDataSource1" 
    onselectedindexchanged="GridView1_SelectedIndexChanged" Height="189px" 
    Width="271px" SelectedIndex="1" ondatabound="GridView1_DataBound">
        <asp:CommandField ShowEditButton="True" />
        <asp:BoundField DataField="ItemID" HeaderText="ItemID" 
            SortExpression="ItemID" ReadOnly="True"/>
        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" 
        <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" 
        <asp:BoundField DataField="Quantity" HeaderText="Quantity" 
            SortExpression="Quantity" />
        <asp:BoundField DataField="CartID" HeaderText="CartID" InsertVisible="False" 
            ReadOnly="True" SortExpression="CartID" Visible="False" />
  <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
 <!--UpdateCommand="UPDATE [Cart] SET [ItemID] = @ItemID, [Name] = @Name, [Price] = @Price, [Quantity] = @Quantity WHERE [CartID] = @original_C artID AND [ItemID] = @original_ItemID AND [Name] = @original_Name AND [Price] = @original_Price AND [Quantity] = @original_Quantity"-->
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:BookStoreConnectionString %>" 
    DeleteCommand="DELETE FROM [Cart] WHERE [CartID] = @original_CartID AND [ItemID] = @original_ItemID AND [Name] = @original_Name AND [Price] = @original_Price AND [Quantity] = @original_Quantity" 
    InsertCommand="INSERT INTO [Cart] ([ItemID], [Name], [Price], [Quantity]) VALUES (@ItemID, @Name, @Price, @Quantity)" 
    SelectCommand="SELECT ItemID, Name, Price, Quantity, CartID FROM Cart WHERE  Quantity>0 AND CustID= @abc">

I’m a bit unclear on what you’re asking. Are you looking for a way to get/set a Session value in a typesafe way, or something else? Usually though, for carts, I don’t use a db table at all. Just create some classes called Cart and Item with the appropriate properties, and have the Cart class implement ICollection<Item>. Then just create and extension method on Session to get/set it. Just be mindful of whether your session object is based on HttpSessionState or HttpSessionStateBase, and do something like this:

public static class SessionExtensions

public static Cart GetCart(this HttpSessionState session)
{ // if cart exists return it, otherwise return new cart
Cart cart = session[“cart”] as Cart;
return temp == null ? new Cart() : cart;

public static void SetCart(this HttpSessionState session, Cart cart)
session[“cart”] = cart;


You can then use linq to select items from the cart and set your grids datasource from that in your code-behind. If I’m way off just let me know.