protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int rowindex = Convert.ToInt32(e.CommandArgument); int adjid = Int32.Parse(((Label)GridView2.Rows[rowindex].FindControl("Label1")).Text); using (LastADEntities entities = new LastADEntities()) { AdjVoucher abc = entities.AdjVouchers.Where(p => p.AdjVoucherId == adjid).First(); if (e.CommandName == "Issue Voucher") { abc.ApprovedDate = DateTime.Now; //abc.ApprovalEmpNum = ... abc.Status = "Authorised"; entities.SaveChanges(); Transaction trans = new Transaction(); string itemname = ((Label)GridView2.Rows[rowindex].FindControl("Label3")).Text; string ItemId = Business.Finditemidbyname(itemname); trans.ItemId = ItemId; int Quantity = Int32.Parse(((Label)GridView2.Rows[rowindex].FindControl("Label4")).Text); trans.Quantity = Quantity; ItemList i = entities.ItemLists.Find(ItemId); int stock = (int)i.Stock; int Balance = stock + (Quantity); trans.Balance = Balance; trans.AdjVoucherId = adjid; trans.EntryDate = DateTime.Now; entities.Transactions.Add(trans); entities.SaveChanges(); GridView2.DataBind(); ItemList xyz = entities.ItemLists.Where(p => p.ItemId == ItemId).First(); xyz.Stock = Balance; entities.SaveChanges(); Response.Redirect("~/6StoreSupervisor/SupervisorAdjVoucher.aspx"); } else if (e.CommandName == "Inform Manager") { abc.Status = "PendingDHAuthorisation"; entities.SaveChanges(); Response.Redirect("~/6StoreSupervisor/SupervisorAdjVoucher.aspx"); } } }