string query = "select Products.ProductID,Products.ProductName,Products.UnitCost,ShoppingCart.Quantity from Products RIGHT JOIN ShoppingCart on Products.ProductID=ShoppingCart.ProductID where CustomerID='"+User.Identity.Name+"'";
protected void btnupdatecart_Click(object sender, EventArgs e) { try { for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { GridViewRow row = GridView1.Rows[i]; if (row.RowType == DataControlRowType.DataRow) { ShoppingCartItem item = new ShoppingCartItem(); item.CustomerID = User.Identity.Name; //item.ProductID = (int)GridView1.DataKeys[i].Value; item.ProductID = int.Parse(((Label)(row.FindControl("lblproid"))).Text); item.Quantity = int.Parse(((TextBox)(row.FindControl("txtdmainqty"))).Text); if (item.Quantity <= 0) { throw new Exception("Invalid Quantity"); } ShoppingCart.UpdateItem(item); } } // GridView1.DataBind(); bind(); btnplaceorder.Enabled = true; //lblMsg.Text = ""; } catch (Exception ex) { btnplaceorder.Enabled = false; //lblMsg.Text = ex.Message; } } private decimal decTotal; protected void _rowdatabound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //int prodid = int.Parse(e.Row.Cells[0].Text); int prodid=int.Parse(((Label)(e.Row.FindControl("lblproid"))).Text); int qty = int.Parse(((TextBox)(e.Row.FindControl("txtmainqty"))).Text); Product p = Product.GetProduct(prodid); decTotal = decTotal + (qty * p.UnitCost); } if (e.Row.RowType == DataControlRowType.Footer) { ((Label)(e.Row.FindControl("lbltotal"))).Text = "Total :" + decTotal.ToString("C"); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)