52,782
社区成员
发帖
与我相关
我的任务
分享$(document).ready(function () {
$('#example').dataTable({
"bProcessing": true,
"sAjaxSource": "Default2.aspx",
});
});$(document).ready(function () {
$('#example').dataTable({
"bProcessing": true,
"sAjaxSource": "WebService.asmx/GetDataSet",
});
});
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string JSON_Data = "{\"aaData\": [";
DataSet ds = AccessHelper.GetData("select id,公司,姓氏,名字,职务 from 客户");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
JSON_Data += "[\"" + ds.Tables[0].Rows[i].ItemArray[0].ToString() + "\",\"" + ds.Tables[0].Rows[i].ItemArray[1].ToString() + "\",\"" + ds.Tables[0].Rows[i].ItemArray[2].ToString() + "\",\"" + ds.Tables[0].Rows[i].ItemArray[3].ToString() + "\",\"" + ds.Tables[0].Rows[i].ItemArray[4].ToString() + "\"],";
}
JSON_Data = JSON_Data.TrimEnd(',') + "]}";
Response.Write(JSON_Data);
Response.End();
}
}
public string GetDataSet()
{
string JSON_Data = "{\"sEcho\":1,\"iTotalRecords\":10,\"iTotalDisplayRecords\":10,\"aaData\": [";
DataSet ds = AccessHelper.GetData("select id,公司,姓氏,名字,职务 from 客户");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
JSON_Data += "[\"" + ds.Tables[0].Rows[i].ItemArray[0].ToString() + "\",\"" + ds.Tables[0].Rows[i].ItemArray[1].ToString() + "\",\"" + ds.Tables[0].Rows[i].ItemArray[2].ToString() + "\",\"" + ds.Tables[0].Rows[i].ItemArray[3].ToString() + "\",\"" + ds.Tables[0].Rows[i].ItemArray[4].ToString() + "\"],";
}
JSON_Data = JSON_Data.TrimEnd(',') + "]}";
return JSON_Data;
}
$(document).ready(function () {
$('#example').dataTable({
"bProcessing": true,
"sAjaxSource": "WebService.asmx/GetDataSet",
"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
});
}
});
});
$(document).ready(function () {
$('#example').dataTable({
"bProcessing": true,
"dataType"="json",
"sAjaxSource": "WebService.asmx/GetDataSet"
});
});