If the user clicks "Edit", ShowAddNewRecordButton is set to 'False' and I rebind the grid.
If the user clicks "Add New Record", e.Item.Edit is set to 'False' and I rebind the grid.
In effect, this means that the user cannot access the 'edit' and 'add new' forms at the same time. Only one can ever be open. I do this for a couple of reasons.
Firstly, if the user tries to add a record AND edit a record (both the 'add new' and 'edit' forms are open simultaneously), if the user tries to submit the edited record first, the validation on the 'add new record' form fires - preventing the edit from occuring.
Secondly, I have controls which I want to appear when the user adds a new record, but I want hidden when they edit a record. I've been able to program the grid to hide the controls If the user edits a record, BUT if the user edits a record THEN clicks the 'adds new' button (whilst the edit form is still expanded), the controls show in both the add new AND - unfortunately - the edit forms.
By controlling access to the "Edit" and "Add New" forms so only one can be open at any one time, this resolves the above issues. Unfortunately, I have a DetailTable which I'm also trying to program to behave the same way but I don't know how to reference the ShowAddNewRecordButton value when it's within a DetailTable. Also, when I rebind the grid, it loses the expanded row (which you'd expect). Any ideas? My code is below...
Protected Sub rdgRiskType_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rdgRiskType.ItemCommand
'If user inserts a new Risk Type record, set 'edit' mode to false and rebind (all 'edit' forms will be minimised).
If e.CommandSource.Text = "Add New Risk Type" Then
e.Item.Edit = False
rdgRiskType.Rebind()
End If
'If user edits a Risk Type record, hide the 'Add New xxx' button (user can't then add a new record whilst an edit form is maximised).
If e.CommandSource.Text = "Edit" Then
rdgRiskType.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = False
rdgRiskType.MasterTableView.IsItemInserted = False
rdgRiskType.Rebind()
End If
'If user inserts a new Risk record, set 'edit' mode to false and rebind (all 'edit' forms will be minimised).
If e.CommandSource.Text = "Add New Risk" Then
End If
'If user edits a Risk record, hide the 'Add New xxx' button (user can't then add a new record whilst an edit form is maximised).
If e.CommandSource.Text = "Edit Risk" Then
End If
End Sub