Hi Telerik Team,
I am using batch edit grid.
My requirement: I want to restrict the user to add new records when the number of records in grid view is more than the Some Quantity (Eg:-2 records).
Below is the code
Note:-Quantity is dynamically Vairing value
ASPX:
<
telerik:RadGrid
ID
=
"gvSerialNumberTracking"
GridLines
=
"None"
runat
=
"server"
AllowPaging
=
"false"
OnBatchEditCommand
=
"gvSerialNumberTracking_BatchEditCommand"
OnItemCommand
=
"gvSerialNumberTracking_ItemCommand"
CssClass
=
"gvPLC"
>
<
MasterTableView
DataKeyNames
=
"SerialNumber_ID,SerialNumber_DJ_ID"
TableLayout
=
"Auto"
EditMode
=
"Batch"
AutoGenerateColumns
=
"false"
CommandItemDisplay
=
"Top"
ClientDataKeyNames
=
"SerialNumber_ID"
>
<
BatchEditingSettingsEditType
=
"Row"
/>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"UnitSN"
HeaderText
=
"Unit SN"
HeaderStyle-Width
=
"100px"
UniqueName
=
"UnitSN"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumnDataField
=
"Sub1"
HeaderText
=
"Sub1"
HeaderStyle-Width
=
"100px"
UniqueName
=
"Sub1"
></
telerik:GridBoundColumn
<
telerik:GridBoundColumnDataField
=
"Sub2"
HeaderText
=
"Sub2"
HeaderStyle-Width
=
"100px"
UniqueName
=
"Sub2"
></
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
AllowKeyboardNavigation
=
"true"
>
<
ClientEvents
OnRowCreating
=
"OnRowCreating"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
function OnRowCreating(sender, args)
{
var grid = $find("<%=gvSerialNumberTracking.ClientID %>");
var MasterTable = grid.get_masterTableView();
var Rows = MasterTable.get_dataItems();
var Qty = $("#txtJQuantity").val()
// txtJQuantity is the quantity (in our case its 2)
if ((Rows.length) > ($("#txtJQuantity").val()))
{
//alert('Wait! You cannot add more than ' + $("#txtJQuantity").val() + ' items');
//args.set_cancel(true);
}
}
Sandeep