New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
Determine insert or edit mode in RadGrid with Batch editing
DESCRIPTION
There are scenarios where it might be helpful to know whether the currently opened grid cell in Batch editing is from a new row or already existing one. Here are some samples:
- When you want your users to be able to insert but not to edit records, or vice versa.
- When you want to save user changes to database explicitly and want to determine whether they are coming from new or already existing row.
- When you want to prefill some values in insert mode depending on other field values.
SOLUTION
You can achieve this requirement using the approach demonstrated below. The provided snippet uses the following event handler for a sample:
OnBatchEditOpened.
Here is the logic:
ASP.NET
<ClientSettings>
<ClientEvents OnBatchEditOpened="batchEditOpened" />
</ClientSettings>
JavaScript
function batchEditOpened(sender, args) {
args.get_tableView().get_dataItems();
var item = args.get_row().control;
if (item.get_itemIndex() < 0) { // new row
// execute custom logic
}
}