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 06:03 AM

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, 


  <div> 
        <ej:Button ID="Button" runat="server" Size="Normal" Type="Reset" ClientSideOnClick="btnClick" ShowRoundedCorner="true" Text="Add"></ej:Button> 
 
    </div> 
 
    <div> 
        <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> 
            <Columns> 
……………… 
 
            </Columns> 
        </ej:Grid> 
    </div> 
    <script> 
        function btnClick(args) { 
            $.ajax({ 
                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) { 
                } 
            }); 
 
        } 
    </script> 
 
Server End method 

   [WebMethod] 
        [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. 

Regards, 
Manivannan Padmanaban. 


Loader.
Live Chat Icon For mobile
Up arrow icon