protected void Search_Click(object sender, EventArgs e) { if (ProductList.SelectedIndex == 0) { errmsgs.Add("You must select a product to search."); LoadMessageDisplay(errmsgs, "alert alert-warning"); } else { try { Product prod = new Product(); ProductController prodcont = new ProductController(); prod = prodcont.Product_Find(int.Parse(ProductList.SelectedValue)); if (prod == null) { errmsgs.Add("That product can no longer be found. Please try again."); LoadMessageDisplay(errmsgs, "alert alert-warning"); ProductDataBind(); } else { ProductName.Text = prod.Name; ModelNumber.Text = prod.ModelNumber; Discontinued.Checked = prod.Discontinued; DiscontinuedDate.Text = string.Format("{0:MMM dd, yyyy}", prod.DiscontinuedDate); List <Registration> regs = new List <Registration>(); RegistrationController regcont = new RegistrationController(); regs = regcont.Registration_GetByProduct(prod.ProductID); RegistrationsGrid.DataSource = regs; RegistrationsGrid.DataBind(); } } catch (DbUpdateException ex) { UpdateException updateException = (UpdateException)ex.InnerException; if (updateException.InnerException != null) { errmsgs.Add(updateException.InnerException.Message.ToString()); } else { errmsgs.Add(updateException.Message); } LoadMessageDisplay(errmsgs, "alert alert-danger"); } catch (DbEntityValidationException ex) { foreach (var entityValidationErrors in ex.EntityValidationErrors) { foreach (var validationError in entityValidationErrors.ValidationErrors) { errmsgs.Add(validationError.ErrorMessage); } } LoadMessageDisplay(errmsgs, "alert alert-danger"); } catch (Exception ex) { errmsgs.Add(GetInnerException(ex).ToString()); LoadMessageDisplay(errmsgs, "alert alert-danger"); } } }