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

button click - jquery json - read all grid records code behind

Hi


It's  possible button click - jquery json - read all grid records code behind ?


foreach (Syncfusion.JavaScript.Models.Column gridCol in (dynamic)gridModel.Columns)
              {
                 object cellText = gridData.GetType().GetProperty(gridCol.Field).GetValue(gridData, null);
                 string header = gridCol.HeaderText;
           }


Thanks

Pratheep



Attachment: WebApplication1_7aedbaa6.rar

3 Replies

MS Mani Sankar Durai Syncfusion Team October 3, 2016 09:33 AM UTC

Hi Pratheep, 

Thanks for contacting Syncfusion support, 

We have analyzed your query and we can get the grid records using button server side events.  

Please refer the below code example, 
[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; 
             
             
        } 

From the above code example we can get the grid records to server side by getting it from the grid ID. 
In the sample click the “Read the data to server” button and get the records to code behind. 

Also please refer the screenshot 

 

We have also modified your sample that can be downloaded from the below link, 

Please let us know if you need further assistance 

Regards, 
Manisankar Durai. 



PR Pratheep October 3, 2016 10:26 AM UTC

Hi

Thank you for your supporting.

Can i get grid data through  WebMethod (Json)? using HTML button (with out run at server)

Thanks
Pratheep


MS Mani Sankar Durai Syncfusion Team October 4, 2016 11:06 AM UTC

Hi Pratheep, 

We have analyzed your query and achieved your requirement to read the grid dataSource without using runat server for the HTML button by passing external AJAX Post to the server in the client click of button. 

Please refer the below code example, 
[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 }; 
         
   } 
} 

In the above code example we have passed the grid dataSource to the server side using external AJAX post when clicking the button. In the server side we can get the grid data. 

We have also prepared a sample that can be downloaded from the below link, 

Please let us know if you need further assistance. 

Regards, 
Manisankar Durai. 


Loader.
Live Chat Icon For mobile
Up arrow icon