You can fine tune the behavior of Telerik RadGrid when inserting/editing items. Consider the scenarios below:
Update to Insert mode
A selected item is in edit mode. You click the "Add New Record" button, the edited record closes and after that the new item is inserted. This is accomplished by
the following code:
| C# |
Copy Code |
|
private void RadGrid1_ItemCommand(object
source, GridCommandEventArgs e)
{
RadGrid grid = (source as RadGrid);
if (e.CommandName == RadGrid.InitInsertCommandName)
{
if (grid.EditItems.Count > 0)
{
grid.MasterTableView.ClearEditItems();
}
}
}
|
| VB.NET |
Copy Code |
|
Private Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs)
Dim grid As RadGrid = CType(source,RadGrid)
If (e.CommandName = RadGrid.InitInsertCommandName) Then
If (grid.EditItems.Count > 0) Then
grid.MasterTableView.ClearEditItems
End If
End If
End Sub
|
Update to Insert mode and Insert to Update mode
This is extended version of the previous case. Here is the new part:
You click "Add New Record" button and a new record is inserted in Telerik RadGrid. Then you click the edit button at another record. The selected item
goes in edit mode and the insert new record closes. You should modify the setting for the IsItemInserted property of the respective
GridTableView:
| C# |
Copy Code |
|
private void RadGrid1_ItemCommand(object
source, Telerik.Web.UI.GridCommandEventArgs e)
{
RadGrid grid = (source as RadGrid);
if(e.CommandName == RadGrid.InitInsertCommandName)
{
grid.MasterTableView.ClearEditItems();
}
if(e.CommandName == RadGrid.EditCommandName)
{
e.Item.OwnerTableView.IsItemInserted = false;
}
}
|
| VB.NET |
Copy Code |
|
Private Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As
Telerik.Web.UI.GridCommandEventArgs)
Dim grid As RadGrid = CType(source,RadGrid)
If (e.CommandName = RadGrid.InitInsertCommandName) Then
grid.MasterTableView.ClearEditItems
End If
If (e.CommandName = RadGrid.EditCommandName) Then
e.Item.OwnerTableView.IsItemInserted = false
End If
End Sub
|