shrish pulkit

shrish pulkit

  • NA
  • 8
  • 3.4k

Unable to show total sum in datalist

Jul 3 2015 1:45 AM
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"  

Answers (6)