protected void RadGrid1_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridEditFormItem editForm    = (GridEditFormItem)e.Item;
        Hashtable        newValues   = new Hashtable();
        XMLContext       context     = new XMLContext();
        XDocument        document    = context.LoadDocument(GetPath());
        List <XElement>  ordersTable = context.GetTable(document, "Orders").ToList();

        //Extract the new values from the editor controls
        editForm.ExtractValues(newValues);
        XElement orderToInsert = new XElement("Order");
        int      orderID       = int.Parse((from order in ordersTable
                                            select order).LastOrDefault().Attribute("OrderID").Value);

        orderToInsert.Add(new XAttribute("OrderID", ++orderID));
        context.InsertElement(document, ApplyChanges(orderToInsert, newValues), "Orders");
        context.SaveChanges(document, GetPath());
    }
    protected void RadGrid1_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridEditFormItem editForm    = (GridEditFormItem)e.Item;
        Hashtable        newValues   = new Hashtable();
        XMLContext       context     = new XMLContext();
        XDocument        document    = context.LoadDocument(GetPath());
        List <XElement>  ordersTable = context.GetTable(document, "Orders").ToList();

        //Extract the new values from the editor controls
        editForm.ExtractValues(newValues);

        //Get the "Primary key" value that will be used to perform CRUD operations
        string orderID = editForm.GetDataKeyValue(RadGrid1.MasterTableView.DataKeyNames[0]).ToString();
        //Get a reference to the modified record
        XElement orderToUpdate = (from order in ordersTable
                                  where order.Attribute("OrderID").Value == orderID
                                  select order).FirstOrDefault();

        context.UpdateElement(ordersTable, ApplyChanges(orderToUpdate, newValues));
        context.SaveChanges(document, GetPath());
        ;
    }