This is a migrated thread and some comments may be shown as answers.

Problem while restricting Add New Record button in BatchEdit RadGrid

1 Answer 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sandeep
Top achievements
Rank 1
Sandeep asked on 09 May 2016, 05:24 AM

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);
  
  
}
}

Thanks and Regards,
Sandeep

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 12 May 2016, 05:35 AM
Hi Sandeep,

I've already replied to your query in the following thread:
http://www.telerik.com/forums/problem-while-restricting-add-new-record-button-in-radgrid

I recommend following the suggested action there.

Regards,
Eyup
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Sandeep
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or