can't generate data in json format in server side scripting
can't generate data in json format in server side scripting
joechungath
Posts: 3Questions: 0Answers: 0
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" }
]
});
});
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" }
]
});
});
This discussion has been closed.
Replies
Allan
Uploading data to the server..." for ages..Don't know what went wrong?
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