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.
Unfortunately, activation email could not send to your email. Please try again.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

126226 Oct 2,2016 07:56 PM Oct 4,2016 07:06 AM ASP.NET Web Forms 3
loading
Tags: Grid
Pratheep
Asked On October 2, 2016 07:56 PM

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

Mani Sankar Durai [Syncfusion]
Replied On October 3, 2016 05:33 AM

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. 


Pratheep
Replied On October 3, 2016 06:26 AM

Hi

Thank you for your supporting.

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

Thanks
Pratheep

Mani Sankar Durai [Syncfusion]
Replied On October 4, 2016 07:06 AM

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. 


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.

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.

;