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

PerformInsert OnCommand

1 Answer 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
MikeL
Top achievements
Rank 1
MikeL asked on 23 Mar 2009, 03:10 PM
I want to by able to Add a record to my datagrid using Ajax.

I'm using inline EditMode and the GridEditCommandColumn.
                            <rad:GridEditCommandColumn ButtonType="ImageButton" UpdateImageUrl="~/RadControls/Grid/Skins/WebBlue/Update.gif"
                                EditImageUrl="~/RadControls/Grid/Skins/WebBlue/Edit.gif" InsertImageUrl="~/RadControls/Grid/Skins/WebBlue/Insert.gif" CancelImageUrl="~/RadControls/Grid/Skins/WebBlue/Cancel.gif"
                                UniqueName="EditCommandColumn" >
                            </rad:GridEditCommandColumn>


I need the Ajax request come to back to my codebehind page to perform the addition and then rebind. Is it possible to do something like this? (Hooked into the <ClientEvents OnCommand> If so, how do I get the values of the newly added row?

        function RaiseCommand(sender, args) { 
            if (args.get_commandName() === "PerformInsert") { 
                $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest('PerformInsert:' + <<NEEDVALUES>>); 
            } 
        } 
 
 

Or is there an easier way???

Many Thanks
Mike

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 26 Mar 2009, 10:47 AM
Hello MikeL,

You can get a reference to the insert form for the new item in code-behind (in the event handler for the ajax request event) and then extract the values for the item:
       GridEditableItem item =  RadGrid1.MasterTableView.GetInsertItem();  
       Hashtable table = new Hashtable();  
       ((Telerik.Web.UI.GridEditFormInsertItem)(item)).ExtractValues(table);  
       item.OwnerTableView.IsItemInserted = false;  
       RadGrid1.MasterTableView.Rebind(); 

However, having in mind that the above apporach won't be able to bypass the page life cycle, you might as well just ajaxify your grid and use the ItemCommand or the InsertCommand event.

I hope these notes were helpful to you.

Best Regards,

Tsvetoslav
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
MikeL
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or