我一直试图让我的jtable从aspx c#代码开始工作。我想是ASP.net。
但是在用了几天搞乱之后,我仍然无法弄清楚在运行aspx时我犯了哪个错误给了我这个错误。:
与服务器通信时发生错误。
以下是我所做的脚本。它正在启动jtable以及List,Create,Delete和Update所需的操作列表。
<script type="text/javascript">
$(document).ready(function () {
//Prepare jtable plugin
$('#UserTableContainer').jtable({
title: 'User Management System',
paging: false,
pageSize: 20,
sorting: true,
defaultSorting: 'userName',
actions: {
listAction: '/administrator/ADMUser.aspx/userList',
createAction: '/administrator/ADMUser.aspx/userCreate',
updateAction: '/administrator/ADMUser.aspx/userUpdate',
deleteAction: '/administrator/ADMUser.aspx/userDelete'
},
fields: {
userId: {
key: true,
create: false,
edit: false,
list: false
},
userName: {
title: 'Username',
width: '23%',
create: true,
edit: false,
list: true
},
userFullname: {
title: 'Full Name',
width: '23%',
create: true,
edit: true,
list: true
},
userEmail: {
title: 'Email address',
list: true,
create: true,
edit: true
},
userPassword: {
title: 'User Password',
type: 'password',
list: false,
edit: true,
create: true
},
CreatedDate: {
title: 'Date Created',
width: '15%',
type: 'date',
create: false,
edit: false,
list: true,
displayFormat: 'yy-mm-dd'
},
userRole: {
title: 'User Roles',
width: '15%',
create: true,
edit: true,
list: true,
options: '/Administrator/ADMMembersManagement.aspx/GetUserRoles',
sorting: false
}
}
});
$('#UserTableContainer').jtable('load');
});
</script>
然后,接下来是具有方法的ASPX.CS代码。
请注意,我将getUserList方法放在UserManager中作为返回用户对象的一个。不确定我是否正确,但我发现有些人尝试使用SQL中的存储过程。但是,我对存储过程不确定,但我已经在普通的SQL查询命令中完成了它。
[WebMethod(EnableSession = true)]
public static object userList(int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
{
try
{
UserManager um = new UserManager();
//Get data from database
List<TemplateUser> students = um.getUserList(jtStartIndex, jtPageSize, jtSorting);
int memberCount = um.TotalNumberOfUsers;
//Return result to jTable
return new { Result = "OK", Records = students, TotalRecordCount = memberCount };
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
return new { Result = "ERROR", Message = ex.Message + "REALLY HERE" };
}
}
最后,我的UserManager代码,我将我的getUserList方法存储在。
中 public List<TemplateUser> getUserList(int inStartIndex, int inPageSize, string inSort)
{
List<TemplateUser> userList = new List<TemplateUser>();
TemplateUser user;
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet();
SqlConnection con = new SqlConnection();
string connString = ConfigurationManager.ConnectionStrings["WEBA_Assignment"].ConnectionString;
con.ConnectionString = connString;
cmd.CommandText = "SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY userName ASC) AS Row, * FROM Users) AS StudentsWithRowNumbers WHERE Row > @inStarIndex AND Row <= @inPageSize ";
cmd.Parameters.Add("@inStartIndex", SqlDbType.Int);
cmd.Parameters["@inStartIndex"].Value = inStartIndex;
cmd.Parameters.Add("@inPageSize", SqlDbType.Int);
cmd.Parameters["@inPageSize"].Value = inPageSize;
da.SelectCommand = cmd;
con.Open();
da.Fill(ds, "UserData");
con.Close();
foreach (DataRow dr in ds.Tables["UserData"].Rows)
{
user = new TemplateUser();
user.userId = int.Parse(dr["userId"].ToString());
user.userName = dr["userName"].ToString();
user.userPassword = dr["userPassword"].ToString();
user.userFullname = dr["userFullname"].ToString();
user.userEmail = dr["userEmail"].ToString();
user.ActivationStatus = int.Parse(dr["ActivationStatus"].ToString());
user.userRole = int.Parse(dr["userRole"].ToString());
int year; int month; int day; int hour; int minute; int second;
year = ((DateTime)dr["CreatedDate"]).Year;
month = ((DateTime)dr["CreatedDate"]).Month;
day = ((DateTime)dr["CreatedDate"]).Day;
hour = ((DateTime)dr["CreatedDate"]).Hour;
minute = ((DateTime)dr["CreatedDate"]).Minute;
second = ((DateTime)dr["CreatedDate"]).Second;
user.CreatedDate = new DateTime(year, month, day, hour, minute, second);
cmd.CommandText = "Select Count(*) 'NumOfRows' FROM Users";
da.SelectCommand = cmd;
con.Open();
da.Fill(ds, "NumOfRows");
con.Close();
TotalNumberOfUsers = int.Parse(dr["NumOfRows"].ToString());
userList.Add(user);
}
return userList;
}//getUserList
我真的很担心这个问题,因为我不确定从哪里开始继续。最初我没有为jtable完成Startindex和Paging,但是我已经看到了其他一些用户的问题,这些问题有必要的答案,然后我将它们放入。< / p>
但仍然......没有结果......