Click here to Skip to main content
15,920,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my script is this

C#
var source = {
             datatype: "json",
             datafields: [{ name: 'ID' }, { name: 'Name' },
             { name: 'Email' }, { name: 'Address' }, { name: 'Contact' }],
             url: "WebForm2.aspx/Grid"
         };




my code behind page is this

C#
public static string DataSetToJSON(DataSet ds)
      {

          Dictionary<string,> dict = new Dictionary<string,>();
          foreach (DataTable dt in ds.Tables)
          {
              object[] arr = new object[dt.Rows.Count + 1];

              for (int i = 0; i <= dt.Rows.Count - 1; i++)
              {
                  arr[i] = dt.Rows[i].ItemArray;
              }

              dict.Add(dt.TableName, arr);
          }

          JavaScriptSerializer json = new JavaScriptSerializer();
          return json.Serialize(dict);
      }
    [WebMethod(EnableSession = false)]
      public static string Grid()
      {
          DataTable dtFormsData = new DataTable();
          DataSet dtFormsDataset = new DataSet();
          dtFormsDataset = new DataSet();
          dtFormsData = new DataTable();
          dtFormsData.Columns.Add("ID");
          dtFormsData.Columns.Add("Name");
          dtFormsData.Columns.Add("Email");
          dtFormsData.Columns.Add("Address");
          dtFormsData.Columns.Add("Contact");
          dtFormsData.Rows.Add(1,"Usha", "Usha@Kp.com", "Chennai", "Kp@guntakal");
          dtFormsData.Rows.Add(2,"Chaitu", "ChaituKp@gmail.com", "Chennai", "ChaituKurava@gmail.com");
          dtFormsData.Rows.Add(3,"UshaSanjee", "Ushasanjee@gmail.com", "Hyderabad", "Hyderabad");
          dtFormsData.Rows.Add(4,"ChaituKP", "chaitu@gmail.com", "Chennai", "Cheenai");
          dtFormsDataset.Tables.Add(dtFormsData);
          string result = DataSetToJSON(dtFormsDataset);
      string[] lines = { dtFormsData.Columns[0].ColumnName, dtFormsData.Columns[1].ColumnName, dtFormsData.Columns[2].ColumnName, dtFormsData.Columns[3].ColumnName, dtFormsData.Columns[4].ColumnName };
      System.IO.File.WriteAllLines(@"C:\Users\ADMIN\My Documents\Visual Studio 2012\Projects\JqxGrid\JqxGrid\WriteLines.txt", lines);
         return result;
      }
Posted
Updated 9-Jun-14 2:06am
v2
Comments
Thanks7872 9-Jun-14 8:33am    
You can find tons of links explaining how to call web method. You should look for how to pass parameters.

you have already posted similar questions as before both has been solved than why again you have asked??

Bind Json data to jqxgrid[^]

Jqxgrid showing window Loading... message,not bale to bind data to Jqxgrid[^]


read them and get solution.. :)
 
Share this answer
 
Comments
Usha Sanjee 9-Jun-14 8:37am    
I worked on the solution u have given its perfect but the problem is I'm working on third party control.I'm not able to achieve the solution u provided me for that.And also the columns or data what ever it should be from code behind.Plz look at tz link
http://stackoverflow.com/questions/10612887/jqxgrid-with-sql-binding-and-largejsonresult-is-empty
which apt to my problem.
you need to reach the result from this line
C#
string result = DataSetToJSON(dtFormsDataset);
by the end of a CALLBACK and then use this line on the client-side

JavaScript
var result = $.parseJSON(e.result);


then breakpoint the result to see what you got.


I would need you to provide your ASPx code for further details.
 
Share this answer
 
Comments
Usha Sanjee 10-Jun-14 0:08am    
<script>
$(document).ready(function () {


var source = {
datatype: "json",
datafields: [{ name: 'ID' }, { name: 'Name' },
{ name: 'Email' }, { name: 'Address' }, { name: 'Contact' }],
url: "WebForm2.aspx/Grid"
};
debugger;
var dataAdapter = new $.jqx.dataAdapter(jsondata);
$("#jqxgrid").empty();
$("#jqxgrid").jqxGrid(
{
width: 670,
source: dataAdapter,
columnsresize: true,
showstatusbar: true,
columns:
[
{ text: 'ID', dataField: 'ID', width: 250 },
{ text: 'Name', dataField: 'Name', width: 250 },
{ text: 'Email', dataField: 'Email', width: 150 },
{ text: 'Address', dataField: 'Address', width: 180 },
{ text: 'Contact', dataField: 'Contact', width: 80 }
]
});

});
});
</script>
<div id="jqxgrid">

</div>

This is aspx code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900