We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Change the Grid to Add mode from code behind

Is there any way to change the grid to Add mode from code behind? I want to remove the Add command from the grid’s toolbar, add my own Button on the form, prepare some data in the button’s event in code behind (c#) and after that change the grid to Add mode.

1 Reply

MP Manivannan Padmanaban Syncfusion Team January 27, 2020 02:03 PM UTC

Hi Ulf, 

Greetings from Syncfusion Support. 

We have achieved your requirement by using the ajax post and addRecord method of ejGrid. We have called the server end method using ajax post and returned the data from sever end, in the ajax success using addRecord method we have inserted the returned data to grid. Refer the below code example, 

        <ej:Button ID="Button" runat="server" Size="Normal" Type="Reset" ClientSideOnClick="btnClick" ShowRoundedCorner="true" Text="Add"></ej:Button> 
        <ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True"> 
            <ToolbarSettings ShowToolbar="True" ToolbarItems="edit,delete,update,cancel"></ToolbarSettings> 
            <EditSettings AllowEditing="true" AllowAdding="true" AllowDeleting="true"></EditSettings> 
        function btnClick(args) { 
                type: "POST", 
                url: "Default.aspx/AddAction", 
                dataType: "json", 
                contentType: "application/json; charset=utf-8", 
                success: function (data) { 
                    var gridObj = $("#OrdersGrid").ejGrid("instance"); // get grid instance using grid ID. 
                    gridObj.addRecord({ "OrderID": data.d[0].OrderID, "CustomerID": data.d[0].CustomerID, "EmployeeID": data.d[0].EmployeeID }); 
                error: function (args) { 
Server End method 

        [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
        public static object AddAction() 
            // do your stuff here. 


Refer the below help documentation link, 

Kindly get back to us, if you need further assistance. We will be happy to assist you. 

Manivannan Padmanaban. 

Live Chat Icon For mobile
Up arrow icon