Click here to Skip to main content
15,886,095 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
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.NET
<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:
ASP.NET
<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:
C#
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 !
Posted
Comments
bbirajdar 4-Nov-12 11:37am    
" problem of displaying the shopping cart smoothly"
"but java script doesn't works"

are not proper technical descriptions of the problem. I don't think you will ever get an answer to your question
Subhabrata Bose 4-Nov-12 11:52am    
First of all check the shopping cart program again without using these popups and every thing. After this is complete then add items one by one with each step testing. Besides shopping cart is the most important and toughest part of an online shopping website. Try it again. Besides I can solve this against a remuneration.

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