Пример #1
0
    protected void RadGrid1_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridEditFormItem item        = (GridEditFormItem)e.Item;
        Contractors      contractors = new Contractors();
        //Create the empty element that should be inserted.
        Customer customerToAdd = new Customer();
        int      customerID;

        int.TryParse(contractors.GetAllCustomers().Last().CustomerID, out customerID);
        //Increment the PK field.
        customerToAdd.CustomerID = (++customerID).ToString();
        //Apply the vlaues from the editor controls.
        item.UpdateValues(customerToAdd);
        //Add the element.
        contractors.AddCustomer(customerToAdd);
    }
Пример #2
0
    protected void RadGrid1_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridEditFormItem item = (GridEditFormItem)e.Item;
        //The collection that should be traversed.
        Contractors     contractors = new Contractors();
        List <Customer> customers   = contractors.GetAllCustomers();
        //Get the PK of the element that should be updated.
        string customerID = item.OwnerTableView.DataKeyValues[item.ItemIndex][RadGrid1.MasterTableView.DataKeyNames[0]].ToString();
        //Query the model for the element that should be updated.
        Customer customerToUpdate = (from customer in customers
                                     where customer.CustomerID == customerID.ToString()
                                     select customer).FirstOrDefault();

        item.UpdateValues(customerToUpdate);
        contractors.UpdateCustomer(customerToUpdate);
    }
    protected void RadGrid1_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridEditFormItem item = (GridEditFormItem)e.Item;

        //Instantiate the model.
        using (NorthwindOpenAccessModel model = new NorthwindOpenAccessModel())
        {
            //Get the primary key value using the DataKeyValue.
            int orderID = int.Parse(item.OwnerTableView.DataKeyValues[item.ItemIndex][RadGrid1.MasterTableView.DataKeyNames[0]].ToString());
            //Query the model for the element that should be updated.
            Order orderToUpdate = (from order in model.Orders
                                   where order.OrderID == orderID
                                   select order).FirstOrDefault();
            //Update the element.
            item.UpdateValues(orderToUpdate);
            //Save the changes back to the model.
            model.SaveChanges();
        }
    }
Пример #4
0
    protected void RadGrid1_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridEditFormItem item = (GridEditFormItem)e.Item;

        //Instantiate the context.
        using (NorthwindEntities context = new NorthwindEntities())
        {
            //Create the empty element that should be inserted.
            Order orderToAdd  = new Order();
            int   lastOrderID = context.Orders.ToList().Last().OrderID;
            //Apply the vlaues from the editor controls.
            item.UpdateValues(orderToAdd);
            //Increment the PK field.
            orderToAdd.OrderID = ++lastOrderID;
            //Add the element.
            context.Orders.AddObject(orderToAdd);
            //Submit the changes back to the context.
            context.SaveChanges();
        }
    }
    protected void RadGrid1_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridEditFormItem item = (GridEditFormItem)e.Item;

        //Instantiate the model.
        using (NorthwindOpenAccessModel model = new NorthwindOpenAccessModel())
        {
            //Get the primary key value using the DataKeyValue.
            int lastOrderID = int.Parse(model.Orders.Last().OrderID.ToString());
            //Create the empty element that should be inserted.
            Order orderToAdd = new Order();
            //Apply the vlaues from the editor controls.
            item.UpdateValues(orderToAdd);
            //Increment the PK field.
            orderToAdd.OrderID = ++lastOrderID;
            //Add the element.
            model.Add(orderToAdd);
            //Save the changes back to the datasource.
            model.SaveChanges();
        }
    }