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

Programmatically Add Insert Record to Grid

4 Answers 254 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 11 Feb 2009, 05:12 PM
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

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Feb 2009, 05:32 AM
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.
0
Princy
Top achievements
Rank 2
answered on 12 Feb 2009, 05:55 AM
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
0
Pau
Top achievements
Rank 1
answered on 12 Feb 2009, 03:49 PM
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
0
Pau
Top achievements
Rank 1
answered on 12 Feb 2009, 03:50 PM
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
Tags
Grid
Asked by
Adam
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Pau
Top achievements
Rank 1
Share this question
or