I am creating a shopping cart. Users would go to individual pages of products and click "add to cart" button. When that button is clicked, the ProductId is stored in an array list in Session["Cart"]. When they go to Cart.aspx, the repeater will display all the items in the array list. I am not sure how to use the array list with an Entity Model properly.
Here is what I have so far for the code-behind:
if (Session["Cart"] != null)
{
using (ProjectEntities myEntities = new ProjectEntities())
{
ArrayList alProduct = new ArrayList();
alProduct = (ArrayList)Session["Cart"];
var product = (from p in myEntities.Products
where p.ProductId == Convert.ToInt32(alProduct)
select new { p.ProductName });
Repeater1.DataSource = product.ToList();
Repeater1.DataBind();
}
}
Here is the markup for Cart.aspx:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table>
<tr>
<td>
<asp:Label ID="lblProductName" runat="server" Text='<%# Eval("ProductName") %>'></asp:Label>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</asp:Content>