示例#1
0
    protected void RadGrid1_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridEditFormItem item = (GridEditFormItem)e.Item;

        //Instantiate the context.
        using (NorthwindLinqToSqlDataContext context = new NorthwindLinqToSqlDataContext())
        {
            //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 context.Orders
                                   where order.OrderID == orderID
                                   select order).FirstOrDefault();
            //Update the element.
            item.UpdateValues(orderToUpdate);
            //Submit the changes back to the context.
            context.SubmitChanges();
        }
    }
示例#2
0
    protected void RadGrid1_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridEditFormItem item = (GridEditFormItem)e.Item;

        //Instantiate the context.
        using (NorthwindLinqToSqlDataContext context = new NorthwindLinqToSqlDataContext())
        {
            //Get the primary key value using the DataKeyValue.
            int lastOrderID = context.Orders.ToList().Last().OrderID;
            //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.
            context.Orders.InsertOnSubmit(orderToAdd);
            //Submit the changes back to the context.
            context.SubmitChanges();
        }
    }