Programmatically Add Insert Record to Grid

5 posts, 0 answers
  1. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 11 Feb 2009 Link to this post

    We have a RadGrid that has the "Add New Record" button in the footer. When we click the link, it adds a new row for inline editing to the grid. This all seems to handled by the grid, as I cannot find any exposed events to override this functionality. That is fine.

    What I need to be able to do though is to call the "Add New Record" functionality from outside of the link that is created in the grid. I want to create a javascript shortcut so that when a person presses certain hotkeys, it will postback or do an ajax request to put in a new editable row, just as the "Add New Record" link does.

    Is this possible and if so, how?

    Thanks,
    Adam
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 11 Feb 2009 Link to this post

    Hi Adam,

    Try using the fireCommand mehod which triggers specific command for the grid when executed.

    JavaScript:
    <script type="text/javascript"
    function addnew() 
        var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView(); 
        masterTable.fireCommand("InitInsert",""); 
    </script> 

    Refer the link for more information about fireCommand.

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 11 Feb 2009 Link to this post

    Hi,

    You can check out the link below  which discusses how to put the row in edit mode  on row double click. You can follow the same approach to put the grid in insert mode and call the "insertItem"  method.

    insertItem:

    Method which inserts new table row to the grid. The new data will be taken from the insertion form editors fields.

    function AddNewItem()
    {
      var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
      masterTable.insertItem();
    }

    Link:  http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editondblclick/defaultcs.aspx

    Thanks,
    Princy
  5. Rob Houck
    Rob Houck avatar
    21 posts
    Member since:
    Jul 2003

    Posted 12 Feb 2009 Link to this post

    The fireCommand worked perfectly for what I was looking for and even ran it through the Ajax Manager that I had assigned to the grid.

    Thanks,
    Rob
  6. Rob Houck
    Rob Houck avatar
    21 posts
    Member since:
    Jul 2003

    Posted 12 Feb 2009 Link to this post

    The fireCommand worked perfectly for what I was looking for and even ran it through the Ajax Manager that I had assigned to the grid.

    Thanks,
    Rob
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017