protected void AddToCart(object sender, ImageClickEventArgs e) { UserControl cart = (UserControl)Master.FindControl("cart1"); DataGrid mydg = (DataGrid)cart.FindControl("dg"); Label lbl = (Label)cart.FindControl("lblTotal"); product = productName; DataTable objDT = (DataTable)Session["Cart"]; foreach (DataRow objDR in objDT.Rows) { if (objDR["product"] == product) { // objDR["Quantity"] = int.Parse(objDR["Quantity"].ToString()) + int.Parse(txtQuantity.Text); objDR["Quantity"] = int.Parse(objDR["Quantity"].ToString()) + 1; blnMatch = true; } } if (blnMatch == false) { objDR = objDT.NewRow(); objDR["Quantity"] = quantity; objDR["Product"] = productName; objDR["Cost"] = Decimal.Parse(productcost); objDT.Rows.Add(objDR); } Session["Cart"] = objDT; mydg.DataSource = objDT; mydg.DataBind(); lbl.Text = "????" + GetItemTotal(); }
Object reference not set to an instance of an object.