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.
<%@ 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>
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)
{
int RestaurantID = int.Parse(Request.QueryString["RestaurantID"]);
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);
DataSet ds = new DataSet();
cmd1.Fill(ds, "Category");
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");
ds.Relations.Add("myrelation", ds.Tables["Category"].Columns["CatID"], ds.Tables["Items"].Columns["CatID"]);
rptCategory.DataSource = ds.Tables["Category"];
Page.DataBind();
cnn.Close();
}
protected void btnClose_Click(object sender, EventArgs e)
{
}
}
}