Untitled


SUBMITTED BY: Guest

DATE: April 18, 2014, 7:23 p.m.

FORMAT: C#

SIZE: 1.8 kB

HITS: 832

  1. protected void CartsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
  2. {
  3. //called when loading the gridview, mostly just changing names of headers and decoding html.
  4. e.Row.Cells[4].Visible = false;
  5. if (e.Row.RowType == DataControlRowType.Header)
  6. {
  7. e.Row.Cells[0].Text = "Remove from cart";
  8. e.Row.Cells[1].Text = "Book Title";
  9. e.Row.Cells[2].Text = "Quantity";
  10. e.Row.Cells[3].Text = "Price";
  11. }
  12. for (int i = 1; i < e.Row.Cells.Count; i++)
  13. {
  14. e.Row.Cells[i].Text = HttpContext.Current.Server.HtmlDecode(e.Row.Cells[i].Text);
  15. }
  16. }
  17. protected void RemoveFromCart(object sender, EventArgs e)
  18. {
  19. //how to remove an item from the cart (and also from the database)
  20. localhost.WebService w = new localhost.WebService();
  21. Connect db = new Connect("userDB.accdb");
  22. LinkButton lb = (LinkButton)sender;
  23. int id = int.Parse(lb.CommandArgument.ToString());
  24. string deletesql = "DELETE FROM cart WHERE orderId=" + id + ";";
  25. string getinfo = "SELECT * FROM cart WHERE orderId = " + id;
  26. DataTable dt = db.MakeConnection(getinfo, "cart");
  27. int quantity = int.Parse(dt.Rows[0]["quantity"].ToString());
  28. int productId = int.Parse(dt.Rows[0]["productId"].ToString());
  29. DataTable dt1 = w.GetDataById(productId);
  30. int stock = int.Parse(dt1.Rows[0]["stock"].ToString());
  31. stock = stock + quantity;
  32. w.Update(stock, productId, "Stock");
  33. db.ConnectInsert(deletesql, "cart");
  34. Response.Redirect("Cart.aspx");
  35. }

comments powered by Disqus