protected void btnCheckOut_Click(object sender, EventArgs e) { for (int i = 0; i < GridView1.Rows.Count; i++) { int OrderItemID = (int)GridView1.DataKeys[i].Value; Label lblProductId = (Label)GridView1.Rows[i].FindControl("Label1"); TextBox txtqty = (TextBox)GridView1.Rows[i].FindControl("txtQty"); try { string str2; str2 = "select * from Product_Master where Product_Id = " + lblProductId.Text; DataTable dt = new DataTable(); dt = objmyclass.GetDataTable(str2); Int32 qty, uqty; qty = Convert.ToInt32(dt.Rows[0]["Quantity"].ToString()); uqty = (Convert.ToInt32(qty) - Convert.ToInt32(txtqty.Text)); objmyclass.con.Open(); string str; str = "UPDATE Product_Master SET Quantity=" + uqty + " WHERE Product_Id=" + lblProductId.Text; SqlCommand cmd = new SqlCommand(str, objmyclass.con); cmd.ExecuteNonQuery(); objmyclass.con.Close(); } catch (Exception ex) { tran.Rollback(); } finally { con.Close(); } } // Response.Redirect("Default2.aspx"); }