<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage/Main.master" AutoEventWireup="true" CodeFile="ShowProduct.aspx.cs" Inherits="Guest_ShowProduct" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <center> <table width="100%"> <asp:DataList ID="dtlist" runat="server" RepeatColumns="4" RepeatDirection="Horizontal" OnItemCommand="dtlist_ItemCommand" OnItemDataBound="dtlist_ItemDataBound"> <ItemTemplate> <table> <tr> <td> <asp:ImageButton ID="imgPic" runat="server" Height="150px" Width="150px" CommandName="Cart" ImageUrl='<%# Eval("image") %>' /> </td> </tr> <tr> <td> <asp:Label ID="lblid" runat="server" Text='<%# Eval("uniqueid")%>'></asp:Label> </td> </tr> <tr> <td> <asp:Label ID="lblProductName" runat="server" Text='<%# Eval("productName")%>'></asp:Label> </td> </tr> <tr> <td> <asp:Label ID="lblPrice" runat="server" Text='<%# Eval("Amount") %>'></asp:Label> </td> </tr> <tr> <td> <asp:LinkButton ID="lnkAdd" runat="server" PostBackUrl="~/Guest/AddToCart.aspx">Add To Cart</asp:LinkButton> </td> </tr> </table> </ItemTemplate> </asp:DataList> </table> </center> </asp:Content>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; public partial class Guest_ShowProduct : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { showproduct(); } } public void showproduct() { d_ProductDetails d = new d_ProductDetails(); DataTable dt = new DataTable(); dt = d.getProduct(); if (dt != null && dt.Rows.Count > 0) { dtlist.DataSource = dt; dtlist.DataBind(); } } public void collectItem() { DataTable dt = new DataTable(); dt.Columns.Add("ProductID", typeof(string)); dt.Columns.Add("ProductName", typeof(string)); dt.Columns.Add("ProductCost", typeof(string)); dt.Columns.Add("ProductImage", typeof(string)); Session["collect"] = dt; } protected void dtlist_ItemDataBound(object sender, DataListItemEventArgs e) { } public void cart() { } protected void dtlist_ItemCommand(object source, DataListCommandEventArgs e) { DataTable dt = (DataTable)Session["collect"]; if (e.CommandName == "Cart") { if (Session["collect"] == null) { DataRow dr = dt.NewRow(); DataList rowSelect = (DataList)(((ImageButton)e.CommandSource).NamingContainer); Label Product = (Label)rowSelect.FindControl("lblProductName"); Label price = (Label)rowSelect.FindControl("lblPrice"); Label id = (Label)rowSelect.FindControl("lblid"); dr["ProductID"] = id.Text; dr["ProductCost"] = price.Text; dr["ProductName"] = Product.Text; dt.Rows.Add(dr); Session["collect"] = dt; } else { var cart = (List<string>)Session["Cart"]; foreach (var product in cart) { cart.Add(product); Session["Cart"] = cart; } } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)