大家好请帮我解决一下
的Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="DemoJTable._default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="/Content/Site.css" rel="stylesheet" type="text/css" />
<link href="/Content/themes/metroblue/jquery-ui.css" rel="stylesheet" type="text/css" />
<!-- jTable style file -->
<link href="/Scripts/jtable/themes/metro/blue/jtable.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/modernizr-2.6.2.js" type="text/javascript"></script>
<script src="/Scripts/jquery-1.9.0.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery-ui-1.9.2.min.js" type="text/javascript"></script>
<script src="/Scripts/jtablesite.js" type="text/javascript"></script>
<!-- A helper library for JSON serialization -->
<script type="text/javascript" src="/Scripts/jtable/external/json2.js"></script>
<!-- Core jTable script file -->
<script type="text/javascript" src="/Scripts/jtable/jquery.jtable.js"></script>
<!-- ASP.NET Web Forms extension for jTable -->
<script type="text/javascript" src="/Scripts/jtable/extensions/jquery.jtable.aspnetpagemethods.js"></script>
</head>
<body>
<div id="jTable"></div>
<script type="text/javascript">
$(document).ready(function () {
$('#jTable').jtable({
title: 'The Student List',
paging: true,
pageSize: 10,
sorting: true,
defaultSorting: 'Name ASC',
actions: {
listAction: '_default.aspx/GetStudents'
//createAction: '/PagingAndSorting.aspx/CreateStudent',
//updateAction: '/PagingAndSorting.aspx/UpdateStudent',
//deleteAction: '/PagingAndSorting.aspx/DeleteStudent'
},
fields: {
Id: {
key: true,
create: false,
edit: false,
list: false
},
Name: {
title: 'Name',
width: '23%'
},
Age: {
title: 'Age',
list: false
},
Email: {
title: 'Email',
list: false
},
Dept: {
title: 'Department',
list: false
},
CityId:{
title: 'City',
width: '12%',
list: false
//options: '/PagingAndSorting.aspx/GetCityOptions'
}
}
});
$('#jTable').jtable('load');
});
</script>
default.cs
using DemoJTable.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DemoJTable
{
public partial class _default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public static DataTable Students()
{
string[] id = { "1", "2", "3", "4" };
string[] name = { "Nguyen Van Cuong", "Ngo Thanh Nguyen", "Ngo Binh Tru", "Le Hoang Khoi" };
string[] age = { "1983", "1986", "1979", "1985" };
string[] email = { "nvc@yahoo.com", "nguyenngo@yahoo.com", "trungo@yahoo.com", "khoile@yahoo.com" };
string[] dept = { "Developer", "Deverloper", "Leader developer", "Developer" };
string[] cityId = { "1", "2", "3", "4" };
DataTable tb = new DataTable();
tb.Columns.Add("Id");
tb.Columns.Add("Name");
tb.Columns.Add("Age");
tb.Columns.Add("Email");
tb.Columns.Add("Dept");
tb.Columns.Add("CityId");
for (int i = 0; i < name.Length; i++)
{
DataRow row = tb.NewRow();
row["Id"] = id[i];
row["Name"] = name[i];
row["Age"] = age[i];
row["Email"] = email[i];
row["Dept"] = dept[i];
row["CityId"] = cityId[i];
tb.Rows.Add(row);
}
return tb;
}
public static DataTable Citys()
{
string[] cityId = { "1", "2", "3", "4", "5" };
string[] cityName = { "Quan 1", "Quan 2", "Quan 3", "Quan 4", "Quan 5" };
DataTable tb = new DataTable();
tb.Columns.Add("CityId");
tb.Columns.Add("CityName");
for (int i = 0; i < cityId.Length; i++)
{
DataRow row = tb.NewRow();
row["CityId"] = cityId[i];
row["CityName"] = cityName[i];
tb.Rows.Add(row);
}
return tb;
}
[WebMethod(EnableSession = true)]
//[WebMethod]
public static object GetStudents(int jtStartIndex, int jtPageSize, string jtSorting)
{
List<Student> colStudent = new List<Student>();
try
{
foreach (DataRow row in Students().Rows)
{
Student stu = new Student();
stu.Id = row["Id"].ToString();
stu.Name = row["Name"].ToString();
stu.Age = row["Age"].ToString();
stu.Email = row["Email"].ToString();
stu.Dept = row["Dept"].ToString();
stu.CityId = row["CityId"].ToString();
colStudent.Add(stu);
}
return new { Result = "OK", Records = colStudent, TotalRecordCount = colStudent.Count };
}
catch (Exception ex)
{
return new { Result = "ERROR", Message = ex.Message };
}
}
}
}
Student.cs
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace DemoJTable.Model
{
public class Student
{
[Required]
public string Id
{
get;
set;
}
[Required]
public string Name
{
get;
set;
}
[Required]
public string Age
{
get;
set;
}
[Required]
public string Email
{
get;
set;
}
[Required]
public string Dept
{
get;
set;
}
[Required]
public string CityId
{
get;
set;
}
}
}
我尝试使用jtable但我有错误:与服务器通信时出错。
这些是我3个文件中的代码。我找不到错误。请帮我找错。
非常感谢大家 阮