Problem while restricting Add New Record button in BatchEdit RadGrid

2 posts, 0 answers
  1. Sandeep
    Sandeep avatar
    6 posts
    Member since:
    Apr 2016

    Posted 09 May Link to this post

    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
  2. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 11 May Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top