Friday, 2 May 2014

showing total items and total price in cart label

No comments
 public void cartcount()
    {
        if (Session["cart"] == null)
        {
            lblcost.Text = "0";
            lblitems.Text = "0";
        }
        else
        {
            DataTable dt = new DataTable();
            dt = (DataTable)Session["cart"];
            int count = dt.Rows.Count;                      
            lblitems.Text=count.ToString();
            int sum = 0;
            foreach (DataRow row in dt.Rows)
            {               
                    sum += Int32.Parse(row["tprice"].ToString());
                    lblcost.Text = sum.ToString();               
            }                       
        }
    }