[Webform2.aspx]
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnProcess" runat="server" Text="Read the Data to server" OnClick="btnProcessStrategy_Click" height="30px" Width="132px" BorderStyle="Double" Font-Size="11px" Font-Names="Arial Narrow" usesubmitbehavior="false"/>
…
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" OnServerEditRow="EditEvents_ServerEditRow" OnServerAddRow="EditEvents_ServerAddRow"
OnServerDeleteRow="EditEvents_ServerDeleteRow">
….
[Webform2.aspx.cs]
public object data;
…
protected void btnProcessStrategy_Click(object sender, EventArgs e)
{
data = this.OrdersGrid.DataSource;
} |
[WebForm2.aspx]
<body>
<form id="form1" runat="server">
<div>
<button type="submit" class="btn btn-success" onclick="serverClick()"><i class="fa fa-check"></i> Read </button>
…
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" OnServerEditRow="EditEvents_ServerEditRow" OnServerAddRow="EditEvents_ServerAddRow"
OnServerDeleteRow="EditEvents_ServerDeleteRow">
…
<script type="text/javascript">
function serverClick() {
var grid = $('#<%= OrdersGrid.ClientID %>').ejGrid("instance");
var object = JSON.stringify(grid.model.dataSource);
$.ajax({
type: "POST",
url: "WebForm2.aspx/ButtonQueries",
datatype: "json",
contentType: "application/json",
data: JSON.stringify({ "grid": object }),
success: function () {
alert("Read the grid record to server");
},
})
}
…
[WebForm2.aspx.cs]
using System.Web.Services;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
…
namespace WebApplication1
{
public partial class WebForm2 : System.Web.UI.Page
{
…
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static object ButtonQueries(string grid)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
IEnumerable gridData = (IEnumerable)serializer.Deserialize(grid, typeof(IEnumerable)); //Retrieves current set of records
return new { result = gridData };
}
}
} |