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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Change the Grid to Add mode from code behind

Thread ID:

Created:

Updated:

Platform:

Replies:

150974 Jan 26,2020 09:14 PM UTC Jan 27,2020 02:03 PM UTC ASP.NET Web Forms 1
loading
Tags: Grid
Ulf
Asked On January 26, 2020 09:14 PM UTC

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.


Manivannan Padmanaban [Syncfusion]
Replied On 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, 


  <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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon