Hi people i am working on a e-commerce project, to store items in shopping cart i have use DataTable with session as given below
(Creating Shopping Cart on page load)
if (Session["basket"] == null)
{
dtcart.Columns.Add(new DataColumn("Productimg", typeof(string)));
dtcart.Columns.Add(new DataColumn("ProductID", typeof(int)));
dtcart.Columns.Add(new DataColumn("Name", typeof(string)));
dtcart.Columns.Add(new DataColumn("Quantity", typeof(int)));
dtcart.Columns.Add(new DataColumn("Price", typeof(string)));
Session["basket"] = dtcart;
}
else
{
dtcart = (DataTable)Session["basket"];
}
(For Adding items to cart i have use following code)
Boolean blnMatch = false;
dtcart = (DataTable)Session["basket"];
foreach (DataRow row in dtcart.Rows)
{
if (int.Parse(row["ProductID"].ToString()) == Convert.ToInt32(lblprodid.Text))
{
row["Quantity"] = (int)row["Quantity"] + 1;
string script = "alert(\"Item Already Added to Shopping Cart.!\");";
ScriptManager.RegisterStartupScript(this, GetType(),"ServerControlScript", script, true);
Session["basket"] = dtcart;
blnMatch = true;
break;
}
}
if (!blnMatch)
{
int qty = 1;
//dtcart.Rows.Add(new object[] { lblprodid.Text, lblprodname.Text, prodImage.ImageUrl.Trim().ToString(), lblprodprice.Text });
dtcart.Rows.Add(new object[] { lblimgsrc.Text, lblprodid.Text, lblprodname.Text,Convert.ToString(qty),lblprodprice.Text});
Session["basket"] = dtcart;
}
On View Cart Page i have used DataList control to view items in shopping cart, However i am able to view all item details except the total amount of shopping cart, it will get updated when i update the quantity, although i already have tried datalist OnItemCommand and OnItemDataBound properties but i am unable to get the desired output.
screen shot of cart is as :
I want this total to be calculated as soon as the product is added to cart, as this is only working with onupdatecommand="DataList1_UpdateCommand"
Vignesh ManiRank #98 · 22.1K reputationPosted Jul 2, 2015, 10:50 PM EDT
shrish pulkit8 reputationPosted Jul 3, 2015, 12:17 AM EDT
Vignesh ManiRank #98 · 22.1K reputationPosted Jul 3, 2015, 12:25 AM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jul 3, 2015, 12:54 AM EDT
shrish pulkit8 reputationPosted Jul 3, 2015, 3:02 AM EDT
shrish pulkit8 reputationPosted Jul 3, 2015, 3:32 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts