protected void CartsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
//called when loading the gridview, mostly just changing names of headers and decoding html.
e.Row.Cells[4].Visible = false;
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Text = "Remove from cart";
e.Row.Cells[1].Text = "Book Title";
e.Row.Cells[2].Text = "Quantity";
e.Row.Cells[3].Text = "Price";
}
for (int i = 1; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Text = HttpContext.Current.Server.HtmlDecode(e.Row.Cells[i].Text);
}
}
protected void RemoveFromCart(object sender, EventArgs e)
{
//how to remove an item from the cart (and also from the database)
localhost.WebService w = new localhost.WebService();
Connect db = new Connect("userDB.accdb");
LinkButton lb = (LinkButton)sender;
int id = int.Parse(lb.CommandArgument.ToString());
string deletesql = "DELETE FROM cart WHERE orderId=" + id + ";";
string getinfo = "SELECT * FROM cart WHERE orderId = " + id;
DataTable dt = db.MakeConnection(getinfo, "cart");
int quantity = int.Parse(dt.Rows[0]["quantity"].ToString());
int productId = int.Parse(dt.Rows[0]["productId"].ToString());
DataTable dt1 = w.GetDataById(productId);
int stock = int.Parse(dt1.Rows[0]["stock"].ToString());
stock = stock + quantity;
w.Update(stock, productId, "Stock");
db.ConnectInsert(deletesql, "cart");
Response.Redirect("Cart.aspx");
}