// The id parameter name should match the DataKeyNames value set on the control public void grdIncidents_UpdateItem(int IncidentID) { Incident item = null; // Load the item here, e.g. item = MyDataLayer.Find(id); TechSupportEntities db = new TechSupportEntities(); item = db.Incidents.Find(IncidentID); if (item == null) { // The item wasn't found ModelState.AddModelError("", String.Format("Item with id {0} was not found", IncidentID)); return; } TryUpdateModel(item); if (ModelState.IsValid) { // Save changes here, e.g. MyDataLayer.SaveChanges(); try { db.SaveChanges(); grdIncidents.DataBind(); } catch (DbUpdateConcurrencyException ex) { HandleConcurrencyError(ex); } catch (DbEntityValidationException ex) { HandleValidationError(ex); } catch (Exception ex) { HandleOtherErrors(ex); } } }
public IQueryable <Customer> ddlCustomers_GetData() { TechSupportEntities db = new TechSupportEntities(); return(from c in db.Customers orderby c.Name select c); }
protected void cstmCustomerID_ServerValidate(object source, ServerValidateEventArgs args) { TechSupportEntities db = new TechSupportEntities(); Customer c = db.Customers.Find(int.Parse(args.Value)); args.IsValid = (c == null) ? false : true; if (!args.IsValid) { ResetProductControls(); } }
// The return type can be changed to IEnumerable, however to support // paging and sorting, the following parameters must be added: // int maximumRows // int startRowIndex // out int totalRowCount // string sortByExpression public IQueryable <Incident> grdIncidents_GetData([Control] string ddlCustomers) { TechSupportEntities db = new TechSupportEntities(); if (ddlCustomers == null) { ddlCustomers = db.Customers.FirstOrDefault().CustomerID.ToString(); } return(from i in db.Incidents where i.CustomerID.ToString() == ddlCustomers select i); }
private void SetupPageForCustomer(int customerID) { TechSupportEntities db = new TechSupportEntities(); selected = db.Customers.Find(customerID); if (selected == null) { return; } Session["customer"] = selected; lblName.Text = selected.Name; btnRegisterProduct.Enabled = true; ddlProducts.Enabled = true; }