protected void rgPartNumbers_UpdateCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == "Update") { using (var context = new cathlabEntities()) { int PNum = int.Parse(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["PartNum"].ToString()); PartNumber pn = context.PartNumbers.Find(PNum); pn.NameSize = (e.Item.FindControl("tbNameSize") as RadTextBox).Text; pn.Cost = int.Parse((e.Item.FindControl("tbCost") as RadTextBox).Text); pn.Par = int.Parse((e.Item.FindControl("tbPar") as RadTextBox).Text); context.SaveChanges(); } } }
protected void rgPartNumbers_DeleteCommand(object sender, GridCommandEventArgs e) { GridDataItem item = (GridDataItem)e.Item; string PartNum = item.GetDataKeyValue("PartNum").ToString(); using (var context = new cathlabEntities()) { PartNumber pn = context.PartNumbers.Find(PartNum); try { context.PartNumbers.Remove(pn); context.SaveChanges(); } catch (DbUpdateException) { rnLabel.Text = "ERROR! Cannot delete, there are products<br/> in the database of that part number."; RadNotification.Show(); } } }