// The id parameter name should match the DataKeyNames value set on the control public void FormViewQuestion_UpdateItem(int id) { try { var context = new ForumEntities(); ForumApp.Models.Question item = context.Questions.FirstOrDefault(a => a.Id == id); // Load the item here, e.g. item = MyDataLayer.Find(id); if (item == null) { // The item wasn't found ModelState.AddModelError("", String.Format("Item with id {0} was not found", id)); return; } TryUpdateModel(item); if (ModelState.IsValid) { // Save changes here, e.g. MyDataLayer.SaveChanges(); context.Entry(item).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } ErrorSuccessNotifier.AddInfoMessage("Question successfuly edited!"); } catch (Exception ex) { ErrorSuccessNotifier.AddErrorMessage("Server Error: " + ex.Message); } }
// The id parameter name should match the DataKeyNames value set on the control public void ListViewAnswers_UpdateItem(int id) { var context = new ForumEntities(); ForumApp.Models.Answer item = context.Answers.FirstOrDefault(a=> a.Id==id); // Load the item here, e.g. item = MyDataLayer.Find(id); if (item == null) { // The item wasn't found ModelState.AddModelError("", String.Format("Item with id {0} was not found", id)); return; } TryUpdateModel(item); if (ModelState.IsValid) { context.Entry(item).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }