Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#ASP.NETSQLAjax
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)
        {
            //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 14-Dec-12 23:07pm

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 840
1 OriginalGriff 508
2 Abhinav S 278
3 thatraja 225
4 Emre Ataseven 200
0 Sergey Alexandrovich Kryukov 8,142
1 OriginalGriff 4,665
2 Peter Leow 3,774
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 15 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid