There were a few problems with the code I posted, most around the type conversion. Anyway, here is the fixed code
private void RadGridHandleChanges(EntityBase entity, GridCommandEventArgs e, bool isUpdate)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
if (!isUpdate && entity.Fields.State != EntityState.Fetched)
{
e.Canceled = true;
return;
}
//Update new values
Hashtable newValues = new Hashtable();
//The GridTableView will fill the values from all editable columns in the hash
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
try
{
IEntityField entityField;
foreach (DictionaryEntry entry in newValues)
{
entityField = entity.Fields[(string)entry.Key];
if (entityField != null)
{
//for some reason, numbers come back as strings, but booleans are really boolean and type converter blows!
if (entry.Value != null && entry.Value.GetType() == entityField.ActualDotNetType)
entity.SetNewFieldValue((string)entry.Key, entry.Value);
else
entity.SetNewFieldValue((string)entry.Key, System.ComponentModel.TypeDescriptor.GetConverter(entityField.ActualDotNetType).ConvertFrom(entry.Value));
}
}
entity.Save();
}
catch
{
e.Canceled = true;
}
}
Call the above code with:
//Inside InsertCommand event
//for insert (e is the parameter from RadGrid_InsertCommabd method)
MyEntity entity = new MyEntity();
RadGridHandleChanges(entity, e, false);
//Inside UpdateCommand event
//for insert (e is the parameter from RadGrid_Update method)
MyEntity entity = new MyEntity(pkey);
RadGridHandleChanges(entity, e, true);
Also, one other note. Make sure AllowAutomaticInsert, AllowAutomaticUpdate, AllowAutomaticDelete are false in your grid.