购物车项目添加花费了太多时间 [英] Cart item add is taking too much of time

查看:94
本文介绍了购物车项目添加花费了太多时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我的aspx页面里有酒店菜单。我需要将项目添加到购物车和购物车显示在同一页面上(到页面的右侧)。将商品添加到购物车需要花费太多时间。您有什么提示我如何快速添加项目?我正在使用sql临时表来保存购物车。



Hello

I have hotel menu in my aspx page. i need to add item to cart and cart is displayed on the same page (to right side of page). It takes too much of time to add item to the cart. Do you have any tips how can i add items quickly. i am using sql temp table to save cart.

wMy code goes like this:
i have a grid displaying categories, inside categories grid i have items grid and inside items grid i have sub items grid. the item that will be added to cart is the sub item. Once i click on add link button, item gets added to cart which itself is a grid, but the problem is it takes many seconds to refresh the cart grid

below is my Design side code:

Menu Items
-------------------------------

<asp:GridView ID="grdCategories" runat="server" AutoGenerateColumns="false" CssClass="menu_items"

                    DataKeyNames="Category" OnRowDataBound="grdCategories_RowDataBound">
                    <Columns>
                        <asp:TemplateField>
                            <ItemTemplate>
                                    <asp:Label ID="lblCategory" runat="server" Text='<%#Eval("Category") %>' Visible="false"></asp:Label>
                                    <asp:Label ID="lblCategoryX" runat="server" Text='<%#Eval("CategoryX") %>'></asp:Label>
                                <asp:Label ID="lblCategoryXX" runat="server" Text='<%#Eval("CategoryXX") %>'></asp:Label>
                                <!--Items in Category -->
                                <asp:GridView ID="grdItems" runat="server" AutoGenerateColumns="false" CssClass="active-grid"

                                    DataKeyNames="Item" OnRowDataBound="grdItems_RowDataBound" ShowHeader="false">
                                    <Columns>
                                        <asp:TemplateField>
                                            <ItemTemplate>
                                                <asp:Label ID="lblItem" runat="server" Text='<%#Eval("Item") %>' Visible="false"></asp:Label>
                                                <asp:Label ID="lblItemX" CssClass="title" runat="server" Text='<%#Eval("ItemX") %>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <ItemTemplate>
                                                <asp:GridView ID="grdSubItems" runat="server" AutoGenerateColumns="false" CssClass=""

                                                    DataKeyNames="SubItem" ShowHeader="false">
                                                    <HeaderStyle HorizontalAlign="Left" />
                                                    <Columns>
                                                        <asp:TemplateField>
                                                            <ItemTemplate>
                                                                <asp:Label ID="lblItem" runat="server" Text='<%#Eval("Item") %>' Visible="false"></asp:Label>
                                                                <asp:Label ID="lblSubItem" runat="server" Text='<%#Eval("SubItem") %>' Visible="false"></asp:Label>
                                                                <asp:Label ID="lblNoofOptions" runat="server" Text='<%#Eval("NumofOptions") %>' Visible="false"></asp:Label>
                                                                <asp:Label ID="lblSubItemX" CssClass="qty" runat="server" Text='<%#Eval("SubItemX") %>'></asp:Label>
                                                            </ItemTemplate>
                                                        </asp:TemplateField>
                                                        <asp:TemplateField>
                                                            <ItemTemplate>
                                                                <asp:Label ID="lblPrice" runat="server" CssClass="price" Text='<%#String.Format("£{0}",Eval("SellingCost")) %>'></asp:Label>
                                                            </ItemTemplate>
                                                        </asp:TemplateField>
                                                        <asp:TemplateField>
                                                            <ItemTemplate>
                                                                <asp:LinkButton ID="lnkAddtoCart" runat="server" OnClick="lnkAddtoCart_Click">Order</asp:LinkButton>
                                                            </ItemTemplate>
                                                            <ItemStyle CssClass="add"></ItemStyle>
                                                        </asp:TemplateField>
                                                    </Columns>
                                                </asp:GridView>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>
                                <!--End Items in Category -->
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <EmptyDataTemplate>
                        <table width="900px">
                            <tr>
                                <td align="center">
                                    <h1>
                                        No Data Available</h1>
                                </td>
                            </tr>
                        </table>
                    </EmptyDataTemplate>
                </asp:GridView>


Cart Grid
--------------------------------
<h2>
                Your Order</h2>
            <div class="order_info">
                <asp:GridView ID="grdOrderDetails" runat="server" PageSize="10" AllowPaging="True"

                    AutoGenerateColumns="False" EnableTheming="True" DataKeyNames="SubItem" OnPageIndexChanging="gvListUpdates_PageIndexChanging"

                    OnRowDeleting="grdOrderDetails_RowDeleting">
                    <Columns>
                        <asp:TemplateField HeaderText="Item" ItemStyle-CssClass="title item">
                            <ItemTemplate>
                                <asp:Label ID="lblItem" runat="server" Text='<%#Eval("Item") %>' Visible="false"></asp:Label>
                                <asp:Label ID="lblSubItem" runat="server" Text='<%#Eval("SubItem") %>' Visible="false"></asp:Label>
                                <asp:Label ID="lblItemX" runat="server" Text='<%#Eval("ItemX") %>'></asp:Label>
                                <asp:Label ID="lblSubItemX" runat="server" Text='<%# string.Format("({0})",  Eval("SubItemX")) %>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle CssClass="item"></ItemStyle>
                            <HeaderStyle CssClass="order_info_title"></HeaderStyle>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Price" ItemStyle-CssClass="title price">
                            <ItemTemplate>
                                <asp:Label ID="lblPrice" runat="server" Text='<%#string.Format("£{0}",  Eval("SellingCost")) %>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle CssClass="price"></ItemStyle>
                            <HeaderStyle CssClass="order_info_title"></HeaderStyle>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Qty" ItemStyle-CssClass="title qty">
                            <ItemTemplate>
                                <asp:Label ID="lblQty" runat="server" Text='<%#Eval("Qty") %>'></asp:Label>
                                <asp:ImageButton ID="imgbtnDelete" runat="server" CssClass="delete" ImageUrl="~/App_Themes/images/delete.png"

                                    CommandName="Delete" CommandArgument="SubItem" CausesValidation="false" />
                            </ItemTemplate>
                            <ItemStyle CssClass="qty"></ItemStyle>
                            <HeaderStyle CssClass="order_info_title"></HeaderStyle>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
                <div class="total">
                    Total: £
                    <asp:Label ID="lblGTotal" runat="server" Text=""></asp:Label>
                </div>
            </div>









Code Behind

------------------------------------------------------







Code Behind
------------------------------------------------------

protected void lnkAddtoCart_Click(object sender, EventArgs e)
    {
        LinkButton lnkOrder = sender as LinkButton;
        GridViewRow gr = (sender as LinkButton).NamingContainer as GridViewRow;
        Label lblItem = gr.FindControl("lblItem") as Label;
        Label lblSubItem = gr.FindControl("lblSubItem") as Label;
        Label lblNoofOptions = gr.FindControl("lblNoofOptions") as Label;

    //sending id of item and subitem
        AddItemToCart(WebHelper.Cast(lblItem.Text, 0), WebHelper.Cast(lblSubItem.Text, 0), 1, "");
    }

/// <summary>
    /// the function will add items to the cart
    /// </summary>
    /// <param name="Item">int Item... ID of the Item to be Added</param>
    /// <param name="SubItem">int SubItem... ID of the SubItem to be Added</param>
    /// <param name="Qty">int Quantity... quantity of the item</param>
    /// <param name="Topings">String Topings.... comma separated ID's of the items to be added as topings</param>
    private void AddItemToCart(int Item, int SubItem, int Qty, String Topings)
    {
        Guid UniqueCartID = new Guid(CargoBag.GetValue("UniqueCartID", Guid.NewGuid().ToString()));


    DataSet aDataSet = new DataSet();
        DataSet ds = new DataSet();
        CartTemTableBL bl = new CartTemTableBL(SessionContext.SystemUser);
        try
        {
            bl.FetchForCart(aDataSet, CartUniqueID);


                DataRow dr = aDataSet.Tables[0].NewRow();
                dr["UniqueCartID"] = CartUniqueID;
                dr["Item"] = Item;
                dr["SubItem"] = SubItem;
                dr["Qty"] = Qty;
                dr["Toppings"] = "";
                dr["OptionItems"] = "";
                aDataSet.Tables[0].Rows.Add(dr);
    }
        catch (Exception ex)
        { }

        return bl.Save(aDataSet);

        FillCartItems();

    }

推荐答案

Well, the answer depends entirely on what you’’ve already done. If it’’s taking forever to add an item to your cart, it’’s probably because you’’re done something very, very wrong in your code. But, since we can’’t see your code and know nothing at all about your implementation, it’’s pretty much impossible for anyone to tell you how to fix it with any accuracy.



The quality of the answer you get is directly dictated by the quality of the question you ask.
Well, the answer depends entirely on what you''ve already done. If it''s taking forever to add an item to your cart, it''s probably because you''re done something very, very wrong in your code. But, since we can''t see your code and know nothing at all about your implementation, it''s pretty much impossible for anyone to tell you how to fix it with any accuracy.

The quality of the answer you get is directly dictated by the quality of the question you ask.


这篇关于购物车项目添加花费了太多时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆