Click here to Skip to main content

Taresh Uppal asked:

Open original thread
Hi All,
 
I am building a project in which I have to give user a functionality of shopping cart. I am able to create a shopping cart but I am getting a problem of displaying the shopping cart smoothly. The issue is that all of my products are inside a data list and on item Command event of data list I am inserting the products into the cart. The popping in and out is done by using java script entity not a function. Now when I use a button with a command name than it picks the new product but java script doesn't works and if I use link button java script works but it doesn't allow me to add anything to cart means cart pops up empty. Where am I getting wrong ???
Is this even a proper way of implementing a shopping cart ??? Here is my data list html mark up :
   <asp:DataList ID="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound"
            OnItemCommand="DataList1_ItemCommand">
            <ItemTemplate>
                <div class="prdt_div">
                    <div class="prd_img">
                        <a class="jqzoom" rel='gal1' title="Earrings"  runat="server" id="img1">
                            <img src="~/images/thumb/er_sm02.jpg" alt=""  runat="server" id="img_thumb" /></a>
                    </div>
                    <div class="prd_descrip">
                        <ul>
                            <li class="titl">
                                <asp:Label runat="server" ID="lbl_ProdName" Text='<%# Eval("Product_Name") %>'></asp:Label></span></li>
                            <li>Our Price: <span>
                                <asp:Label runat="server" ID="lbl_price" Text='<%# Eval("Price_INR") %>'></asp:Label></span></li>
                            <li>Qty:
                                <asp:Label runat="server" ID="lbl_quntity" Text='<%# Eval("Quantity") %>'></asp:Label>
                            </li>
                            <li><a href="" data-reveal-id="myModal"  runat="server" id="order"   önserverclick="anchor1_serverclick">cart show </a>
                            <asp:Button ID="lbkBtnADD" CssClass="order_now" CommandName="Select" runat="server" OnClientClick="data-reveal-id:myModal"></asp:Button>
                                <asp:Label runat="server" ID="lblProdID" Text='<%# Eval("Id") %>' Style="visibility: hidden;"></asp:Label>
                        </ul>
                    </div>
                </div>
            </ItemTemplate>
        </asp:DataList>
 

 
This is my iframe which i pop up using div through javascript:
  <div id="myModal" class="reveal-modal">
            <h2>
                my cart - <span>You now have <span class="item">5 item(s)</span> in your cart</span></h2>
            <iframe src="../shopping-cart.aspx" width="600" height="168" scrolling="auto" frameborder="0">
            </iframe>
            <p class="grand_total">
                Grand Total (INR) : <span>4800</span></p>
            <a class="close-reveal-modal">
                <img src="../images/corss-red.png" /></a>
            <table width="100%">
                <tr>
                    <td>
                    </td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td width="100%" align="right">
                        <span style="padding: 10px 10px 0 0;">
                            <asp:ImageButton ID="imgContiShopping" CssClass="close-reveal-modal continue_shoping"
                                Height="30px" Width="80px" ImageUrl="~/images/Continue.jpeg" runat="server" OnClick="imgContiShopping_Click" /></span>
                        <span style="padding: 10px 10px 0 0;">
                            <asp:ImageButton ID="imgCheckOut" CssClass="close-reveal-modal checkout_bt" Height="30px"
                                Width="80px" ImageUrl="~/images/CheckOut.jpeg" runat="server" OnClick="imgCheckOut_Click" /></span>
                    </td>
                </tr>
            </table>
        </div>
 
And this is my code behind:
 if (e.CommandName == "Select")
        {
            int iProductId = Convert.ToInt32(((Label)e.Item.FindControl("lblProdID")).Text);
            string str_ProdName = Convert.ToString(((Label)e.Item.FindControl("lbl_ProdName")).Text);
            int iQuantity = Convert.ToInt32(((Label)e.Item.FindControl("lbl_quntity")).Text);
            int i_Price = Convert.ToInt32(((Label)e.Item.FindControl("lbl_price")).Text);
            string strImgUrl = Convert.ToString(((HtmlImage)e.Item.FindControl("img_thumb")).Src);
            int iTotal = i_Price * iQuantity;
 
            AddToCart(iProductId, str_ProdName, iQuantity, i_Price, iTotal, strImgUrl);
       
            
            Response.Redirect("../shopping-cart.aspx");
 
           
        }
 
Please help me !
Tags: C#, Javascript, ASP.NET, Ajax

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web03 | 2.8.150128.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100