ReCalculation Button


/ Published in: ASP
Save to your folder(s)

trying to make my calculation button work, i use literal qty


Copy this code and paste it in your HTML
  1. Sir i been study programmer for a month now, yes i still freshie and i find others ppl to help me but they cant solve it. i just need help with my refresh shopping cart list.
  2.  
  3. this is my datatable
  4. --------------------------------------
  5.  
  6. DataTable dt = new DataTable();
  7. dt.Columns.Add("RowID", typeof(int));
  8. dt.Columns.Add("PRD_IMG", typeof(string));
  9. dt.Columns.Add("PRD_CODE", typeof(string));
  10. dt.Columns.Add("PRD_NAME", typeof(string));
  11. dt.Columns.Add("PRD_QTY", typeof(int));
  12. dt.Columns.Add("PRD_AMT", typeof(double));
  13.  
  14. this are my button
  15.  
  16. protected void btnCalculate_Click(object sender, EventArgs e)
  17. {
  18.  
  19. }
  20.  
  21. this i use to populate data table in server i use literal,
  22.  
  23. private void Populate_SC_List(DataTable dt_ShopCart)
  24. {
  25.  
  26. string s_lit = "";
  27. if (dt_ShopCart.Rows.Count <= 0)
  28. {
  29.  
  30. lbl_empty_cart.Text = "<h3>Shopping Cart Is Empty</h3>";
  31.  
  32. return;
  33. }
  34.  
  35. int i_GRANT_QTY = 0;
  36. int i_AddOn_QTY = 0;
  37. double d_GRANT_TOTAL = 0;
  38.  
  39.  
  40.  
  41. //content row
  42. for (int i = 0; i < dt_ShopCart.Rows.Count; i++)
  43. {
  44. int i_qty = Util.CInt(dt_ShopCart.Rows[i]["PRD_QTY"].ToString().Trim());
  45. double d_amt = Util.CDouble(dt_ShopCart.Rows[i]["PRD_AMT"].ToString().Trim());
  46.  
  47. i_GRANT_QTY += i_qty;
  48. d_GRANT_TOTAL += (d_amt * i_qty);
  49.  
  50.  
  51. if (dt_ShopCart.Rows[i]["PRD_CODE"].ToString().Trim().Substring(0, 2) == "AO")
  52. {
  53. i_AddOn_QTY += i_qty;
  54. }
  55.  
  56.  
  57. s_lit += "<tr class='first last odd'>";
  58. s_lit += "<td align='center'><a href=flowerInfo.aspx?pid=" + dt_ShopCart.Rows[i]["PRD_CODE"].ToString().Trim().Substring(0, 5) + " target='_blank'><img src='../productpic/THUMB/" + dt_ShopCart.Rows[i]["PRD_IMG"].ToString().Trim() + "' runat='server' Width='150' /></a></td>";
  59. s_lit += "<td style='text-align:left;'>" + dt_ShopCart.Rows[i]["PRD_NAME"].ToString().Trim() + "</td>";
  60. s_lit += "<dl>";
  61. s_lit += "<dt><strong></strong></dt>";
  62. s_lit += "<dt><strong></strong></dt>";
  63. s_lit += "</dl></td>";
  64. s_lit += "<td align='right'><span class='price'>RM" + Util.CDouble(dt_ShopCart.Rows[i]["PRD_AMT"].ToString()).ToString("#,#0.00") + "</span></td>";
  65. s_lit += "<td class='a-center'>";
  66. s_lit += "<div class='input-qty-box'>";
  67. s_lit += "<div class='input'>";
  68. s_lit += "<ul class='range' >";
  69. s_lit += "<li class='item minus'><a>-</a></li>";
  70. s_lit += "<li>";
  71. s_lit += "<input type='text' maxlength='3' size='2' value='" + dt_ShopCart.Rows[i]["PRD_QTY"].ToString().Trim() + " 'quantity_wanted' onkeypress='return isNumberKey(event)' id='txtQty_" + dt_ShopCart.Rows[i]["RowID"].ToString() + "' >";
  72. s_lit += "</li>";
  73. s_lit += "<li class='item plus'><a>+</a></li>";
  74. s_lit += "</ul>";
  75. s_lit += "</div>";
  76. s_lit += "</div></td>";
  77. s_lit += "<td align='right'><span class='price'>RM " + (i_qty * d_amt).ToString("#,#0.00") + "</span></td>";
  78. s_lit += "<td align='center'><a href=shoppingcart.aspx?a=d&pid=" + dt_ShopCart.Rows[i]["PRD_CODE"].ToString().Trim().Substring(0, 5) + ">x</a></td>";
  79. s_lit += "</tr>";
  80. }
  81.  
  82. int i_QTY = 0;
  83. if (i_GRANT_QTY - i_AddOn_QTY > 0)
  84. i_QTY = i_GRANT_QTY - i_AddOn_QTY;
  85. else
  86. i_QTY = i_AddOn_QTY;
  87.  
  88. hif_i_Qty.Value = i_QTY.ToString();
  89.  
  90. lit_ShopCart.Text = s_lit.Trim();
  91.  
  92. SUB_TOTAL.Text = (d_GRANT_TOTAL).ToString("#,#0.00");
  93. GRANT_TOTAL.Text = (Util.CDouble(hif_SHIP_PRICE_FOOT.Value.Trim()) + d_GRANT_TOTAL).ToString("#,#0.00");
  94. hif_GRANT_QTY.Value = i_GRANT_QTY.ToString();
  95.  
  96.  
  97.  
  98.  
  99. }
  100.  
  101. can it be done? to grab quantity if the user change the quantity the price will change after user click refresh shopping cart button? thanks you sir.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.