Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I'm trying to create a pop-up shopping cart. It's much like a normal shopping cart, however when the user clicks the item I would like to have a popup appear with an input box for the quantity and the add item button. It uses a SQL database that reads from multiple tables that are nested within each other. e.g. Menu > Category > FoodItem > FoodOptions.

The way I currently have it is not the most efficient. I have nested repeaters with an AJAX modal popup that will pull up a panel, which contains the input box for quantity. The problem with this is that the page must render every FoodItem Panel on Page_Load.
So I'm thinking to having each FoodItem OnClick event to fire up the panel and then read the FoodItems child table, FoodOptions and display them on the popup panel.Am I even on the right track? I would really appreciate anyone's input on this. Thanks in advance.

ASP.NET
<%@ Page Title="" EnableEventValidation="false" Language="C#" MasterPageFile="~/OrderInfo.master" AutoEventWireup="true" CodeBehind="Restaurant.aspx.cs" Inherits="DeliverWe.Restaurant" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<%@ Import Namespace="System.Data" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder3" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
       
    </div>
    <div>
        <asp:Repeater ID="rptCategory" runat="server">
            <ItemTemplate>
                <ul>
                    <li>
                        <br />
                        <%#DataBinder.Eval(Container.DataItem, "CatName")%>
                        <%#DataBinder.Eval(Container.DataItem, "CatDescription") %></li>
                    <asp:Repeater ID="rptItem" runat="server" DataSource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>'>
                        <ItemTemplate>
                            <li>
                                <asp:LinkButton ID="lbItem" runat="server"><%#DataBinder.Eval(Container.DataItem, "[\"ItemName\"]")%></asp:LinkButton>
                                <%#DataBinder.Eval(Container.DataItem, "[\"ItemDescription\"]") %>
                                <%#DataBinder.Eval(Container.DataItem, "[\"Price\"]", "{0:c}")%></li>
                            <asp:ModalPopupExtender ID="mpe" runat="server" TargetControlID="lbItem" PopupControlID="ModalPanel">
                            </asp:ModalPopupExtender>
                            <asp:Panel ID="ModalPanel" runat="server" Width="500px" BorderStyle="Double" BackColor="White"
                                Height="500px">
                                <%#DataBinder.Eval(Container.DataItem, "[\"ItemName\"]")%><br />
                                <%#DataBinder.Eval(Container.DataItem, "[\"ItemDescription\"]") %><br />
                                Quantity:
                                <asp:TextBox ID="tbName" runat="server" /><br />
                                
                                Special Instructions:
                                <asp:TextBox ID="txtInstructions" runat="server" /><br />
                                <asp:Button ID="btnClose" runat="server" Text="Close" OnClientClick="javascript:window.parent.hidepopup()" OnClick="btnClose_Click"  />
                            </asp:Panel>
                        </ItemTemplate>
                    </asp:Repeater>
                </ul>
            </ItemTemplate>
        </asp:Repeater>
    </div>
</asp:Content>

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;



namespace DeliverWe
{
    public partial class Restaurant : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //retrieve the value of the query string attribute
            int RestaurantID = int.Parse(Request.QueryString["RestaurantID"]);
            

            //Create the connection and DataAdapter for the Category table.
            SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["DeliverWeConnectionString"].ConnectionString.ToString());
            SqlDataAdapter cmd1 = new SqlDataAdapter("SELECT  Category.CatName, Category.CatDescription, Category.CatID FROM Menu INNER JOIN Category ON Menu.MenuID = Category.MenuID WHERE (Menu.RestaurantID =" + RestaurantID +")", cnn);
            


            //Create and fill the DataSet.
            DataSet ds = new DataSet();
            cmd1.Fill(ds, "Category");

            //Create a second DataAdapter for the Items table.
            SqlDataAdapter cmd2 = new SqlDataAdapter("SELECT Items.ItemName, Items.ItemDescription, Items.Price, Items.CatID FROM Category INNER JOIN Items ON Category.CatID = Items.CatID", cnn);
            cmd2.Fill(ds, "Items");

            //Create the relation bewtween the Category and Items tables.
            ds.Relations.Add("myrelation", ds.Tables["Category"].Columns["CatID"],  ds.Tables["Items"].Columns["CatID"]);

            //Bind the Category table to the parent Repeater control, and call DataBind.
            rptCategory.DataSource = ds.Tables["Category"];
            Page.DataBind();

            

            //Close the connection.
            cnn.Close();

        }
        protected void btnClose_Click(object sender, EventArgs e)
        {
            

            //lblName.Text = HttpUtility.HtmlEncode(tbName.Text);
            //lblEmail.Text = HttpUtility.HtmlEncode(tbEmail.Text);
            
        }
    }
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900