ASP.NET Web Forms: How to reference CheckBoxList items as 'selected' on a table on another page using only C# and ASP.NET web forms?

Assignment Instructions:

Develop a simple shopping cart application that uses session objects to store the information. You will have to create an ASP.NET project that contains two web forms. The first web form, ShoppingCart.aspx, allows the user to select items using a set of checkboxes. This page shows also the number of items in the cart.

The second web form, Display.aspx, displays the number of selected items in a table and allows the user to go back to the first web form and continue shopping.

  • I am using a CheckBoxList to list my products, and I built a table with IDs in the cells to receive the data the user checks off.
  • (I considered the idea of using CheckBox vs. CheckBoxList, but this would not be the appropriate solution and doesn't easily allow counting total items selected)
  • I have tried using cookies and session state variables, but I can't figure out how to associate them to the table.
  • I can transfer test data from labels and textboxes, anything with an ID, but not my CheckBoxList items.

How do I reference which checkboxes are selected on page 1, that will update the desired table cells on page 2, after clicking the 'checkout' button without unique IDs on the list items?

Example: If... 1lb Dark Roast is selected on page 1 ... (identified as 'p001' for product 1 on next page)

<asp:ListItem Value="15.99">1lb Dark Roast</asp:ListItem>

On page 2 (Display.aspx) the Amount column should update to '1' beside that product

<asp:TableCell ID="p001_amt" runat="server"></asp:TableCell>

If an item is checked on page 1, this should be the result... (along with the other products).

Product Price Amount
1lb dark Roast $15.99 1
1lb Med Roast $15.99 0

1 = checked, 0 = unchecked (assignment desired outcome shows this table)

Any help would be appreciated. Thanks.

Here are snippets from my code, if more is needed I can add a link to the full pages.

Page 1 (ShoppingCart.aspx)

<asp:Label ID="TotalCart_lbl" runat="server" Text="Total Items in your Cart: "></asp:Label>
<br />
<asp:CheckBoxList ID="Shop_ckbx" runat="server">
                    <asp:ListItem Value="15.99">1lb Dark Roast</asp:ListItem>
                    <asp:ListItem Value="15.99">1lb Medium Roast</asp:ListItem>
                    <asp:ListItem Value="12.99">1lb Decaf Roast</asp:ListItem>
                    <asp:ListItem Value="16.99">1lb Cold Brew</asp:ListItem>
                    <asp:ListItem Value="10.99">1 box Tea</asp:ListItem>
                    <asp:ListItem Value="35.99">French Press</asp:ListItem>
                    <asp:ListItem Value="8.99">CCM Mug</asp:ListItem>
<br />
<asp:Button ID="UpdateCart_btn" runat="server" Text="Update Your cart" OnClick="UpdateCart_btn_Click"/>
<br />
<asp:Label ID="Contents_lbl" runat="server" Text="Update To See Cart Contents"></asp:Label>
<br />
<asp:Label ID="Cost_lbl" runat="server" Text="Total: "></asp:Label>
<br />
<asp:Button ID="Checkout_btn" runat="server" PostBackUrl="~/Display.aspx" Text="Go to Checkout" />

protected void UpdateCart_btn_Click(object sender, EventArgs e)
         int total = 0; //Total item count

         Contents_lbl.Text = "Your Cart Contains: <br/>- - - - - - - - - - - - - - - -";
         foreach (ListItem listItem in Shop_ckbx.Items)
            if (listItem.Selected == true)
               //Add Text to label
               Contents_lbl.Text += "<br/>&#8226 " + listItem.Text;

               //Count
               total += 1;
         Contents_lbl.Text += "<br/>";

         for (int i = 0; i < Shop_ckbx.Items.Count; i++)
            if (Shop_ckbx.Items[i].Selected)
               cost += Convert.ToDouble(Shop_ckbx.Items[i].Value);
               Cost_lbl.Text = "Total: $ " + cost.ToString();
         //Update total items
         TotalCart_lbl.Text = "Total Items in Your Cart: " + total;

protected void Checkout_btn_Click(object sender, EventArgs e)
          How do I reference the items in the checklist on page 1 
          to update the table on page 2 without unique IDs on each list item?

Page 2 code (Display.aspx)

<asp:Table ID="Display_tbl" runat="server">
                <asp:TableRow runat="server" ID="Header_row" Font-Bold="True" Font-Size="Larger" BackColor="#FFCC99">
                    <asp:TableCell ID="Product_cell" runat="server" Width="250">Product</asp:TableCell>
                    <asp:TableCell ID="Price_cell" runat="server" Width="100">Price</asp:TableCell>
                    <asp:TableCell ID="Amount_cell" runat="server" Width="100">Amount</asp:TableCell>
                <asp:TableRow runat="server" ID="p001">
                    <asp:TableCell ID="p001_prod" runat="server">1lb Dark Roast</asp:TableCell>
                    <asp:TableCell ID="p001_price" runat="server">$ 15.99</asp:TableCell>
                    <asp:TableCell ID="p001_amt" runat="server"></asp:TableCell>
                <asp:TableRow runat="server" ID="p002" Width="500px">
                    <asp:TableCell ID="p002_prod" runat="server">1lb Med Roast</asp:TableCell>
                    <asp:TableCell ID="p002_price" runat="server">$ 15.99</asp:TableCell>
                    <asp:TableCell ID="p002_amt" runat="server"></asp:TableCell>
                <asp:TableRow runat="server" ID="p003">
                    <asp:TableCell ID="p003_prod" runat="server">1lb Decaf</asp:TableCell>
                    <asp:TableCell ID="p003_price" runat="server">$ 12.99</asp:TableCell>
                    <asp:TableCell ID="p003_amt" runat="server"></asp:TableCell>
                <asp:TableRow runat="server" ID="p004">
                    <asp:TableCell ID="p004_prod" runat="server">1lb Cold Brew</asp:TableCell>
                    <asp:TableCell ID="p004_price" runat="server">$ 16.99</asp:TableCell>
                    <asp:TableCell ID="p004_amt" runat="server"></asp:TableCell>
                <asp:TableRow runat="server" ID="p005">
                    <asp:TableCell ID="p005_prod" runat="server">1 box Tea (50 bags)</asp:TableCell>
                    <asp:TableCell ID="p005_price" runat="server">$ 10.99</asp:TableCell>
                    <asp:TableCell ID="p005_amt" runat="server"></asp:TableCell>
                <asp:TableRow runat="server" ID="p006">
                    <asp:TableCell ID="p006_prod" runat="server">French Press</asp:TableCell>
                    <asp:TableCell ID="p006_price" runat="server">$ 35.99</asp:TableCell>
                    <asp:TableCell ID="p006_amt" runat="server"></asp:TableCell>
                <asp:TableRow runat="server" ID="p007">
                    <asp:TableCell ID="p007_prod" runat="server">CCM Coffee Mug</asp:TableCell>
                    <asp:TableCell ID="p007_price" runat="server">$ 8.99</asp:TableCell>
                    <asp:TableCell ID="p007_amt" runat="server"></asp:TableCell>
                <asp:TableRow runat="server" ID="Total_row">
                    <asp:TableCell ID="Total_prod" runat="server">Total</asp:TableCell>
                    <asp:TableCell ID="Total_price" runat="server"></asp:TableCell>
                    <asp:TableCell ID="Total_amt" runat="server"></asp:TableCell>
<asp:LinkButton ID="Back_linkbtn" runat="server" OnClick="Back_linkbtn_Click">Go Back to the Shop</asp:LinkButton>

protected void Page_Load(object sender, EventArgs e)
         ShoppingCart prevPage = PreviousPage as ShoppingCart;
         if (prevPage != null) 
              in order to CONTINUE SHOPPING.

protected void Back_linkbtn_Click(object sender, EventArgs e)