Selecting an item in a GridView and adding to the List
<p>I have written the piece of code below to get a <code>productID</code> from a gridView when the user clicks on the select link.</p>

<p><code>Convert.ToInt32(GridView1.SelectedDataKey.Values["productID"])))</code></p>

<p>However, if a user clicks on this more than one click the newer value replaces the previous. Is there a way to keep adding to the cart list when the user clicks on a new item? </p>

<p>Hope that makes sense</p>

<p>Thanks</p>

<p>Edit:</p>

<p>Here's my code for the Shopping Page:</p>

<pre><code>public partial class _Default : System.Web.UI.Page
{
    List&lt;BasketClass&gt; cart = new List&lt;BasketClass&gt;();

    protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
    {
        cart.Add(new BasketClass(Convert.ToInt32(GridView1.SelectedDataKey.Values["BookID"])));

        Session.Add("CartSess", cart);
        Response.Redirect("Basket.aspx");
    }
}
</code></pre>

<p>I dont know if the location of creating the list is important? Wasn't sure if it was placed in the click event if it would keep creating a new instance?</p>

<p>Then for the Basket Page I have:</p>

<pre><code>protected void Page_Init(object sender, EventArgs e)
{
    List&lt;BasketClass&gt; cart = (List&lt;BasketClass&gt;)Session["CartSess"];

    foreach (BasketClass BookID in cart)
    {     
        GridView1.DataSource = cart;
        GridView1.DataBind();
        AccessDataSource1.SelectCommand = "SELECT [BookID], [book_title] FROM [tblBook] ";                     
    }
}
</code></pre>
