Hi
I am using batch edit grid.
My requirement: I want to restrict the user to create the
new row when the number of rows in grid view is more than the quantity (2
records). And also I want user to edit the existing rows.
I am able to restrict the user from adding new rows more than number of records
specified( In our case its 2 records).
But the problem is I am not able to edit existing rows.
Below is the code.
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
>
Javascript:
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);
}
}
Thanks and Regards,
Sandeep