can't generate data in json format in server side scripting

can't generate data in json format in server side scripting

joechungathjoechungath Posts: 3Questions: 0Answers: 0
edited February 2014 in General
adp.Fill(dataset);
I can't retrieve data into datatable. can someone help me out please
Code behind script
LoadData()
{
str = "{";
str += "\"sEcho\": " + "sEcho" + ",";
str += "\"iTotalRecords\": " + ds.Tables[0].Rows.Count.ToString() + ",";

str += "\"aaData\": [";
bool other = false;
foreach (DataRow row in ds.Tables[0].Rows)
{
if (other == true)
{
str += ",";
}
//str += "[";
str += "\"" + row["EmployeeID"].ToString() + "\",";
str += "\"" + row["FirstName"].ToString() + "\",";
str += "\"" + row["LastName"].ToString() + "\",";
str += "\"" + row["Department"].ToString() + "\",";
str += "\"" + row["Experience"].ToString() + "\",";
str += "\"" + row["Salary"].ToString() + "\"";
str += "]";
other = true;
}
str += "]";
str += "}";
return str;
}
}
public class EmployeeList
{
public int EmployeeID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Department { get; set; }
public int Experience { get; set; }
public int Salary { get; set; }

}
client side script is

$(document).ready(function() {
$('#table_id').dataTable({
"sScrollY": "200px",
"bProcessing": true,
"sPaginationType": "full_numbers",
"sAjaxSource": WebAppDatatablePoc_Default.LoadData(),
"aoColumns": [

{ "mData ": "EmployeeID" }, /* mdata-This property can be used to read data from any JSON data source property*/
{"mData ": "FirstName" },
{ "mData ": "LastName" },
{ "mData ": "Department" },
{ "mData ": "Experience" },
{ "mData ": "Salary" }
]


});
});

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    If you are having a problem with ASP, I'd suggest you ask in an ASP specific forum or StackOverflow.

    Allan
  • joechungathjoechungath Posts: 3Questions: 0Answers: 0
    ok Thanks Allan
  • joechungathjoechungath Posts: 3Questions: 0Answers: 0
    I used a datatable debugger and its showing a message "DataTables debug bookmarklet
    Uploading data to the server..." for ages..Don't know what went wrong?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    How much data was there? Its possible the connection timed out... The debugger can be a little flakily in that way sometimes. Which browser did you do it from - if not Chrome, try it in Chrome.

    Or if you just want to take a look at the JSON data returned, follow the instructions in this tech note: http://next.datatables.net/manual/tech-notes/1

    Allan
This discussion has been closed.