jquery easyUI datagrid在.net中.ashx怎么传值呢?
比如上图,怎么样从sql里面查询所需要的数据,然后让他绑定到datagrid中的。
求高手在空余时空能指导一二。要是能有具体的源代码就好了。在百度上找到的都没有包括数据库的。 jquery datagrid .net sql
[解决办法]
//加载信息
$('#tt').datagrid({
idField: 'id',
url: '../Handler/Department.ashx',
loadMsg: '数据装载中......',
sortName: 'Id',
singleSelect: true,
columns: [[
{ field: 'BelongDepName', title: '部门名称', width: $(this).width() * 0.1 },
{ field: 'BelongDepUser', title: '部门负责人', width: $(this).width() * 0.1 },
{ field: 'BelongDepTel', title: '联系电话', width: $(this).width() * 0.1 },
{ field: 'BelongDepDesc', title: '备注', width: $(this).width() * 0.1 }
]],
pagination: true,
rownumbers: true
});
var p = $('#tt').datagrid('getPager');
$(p).pagination({
pageNumber: 2,
pageSize: 15,//每页显示的记录条数,默认为10
pageList: [15, 20, 30],//页数文本框前显示的汉字
beforePageText: '第',
afterPageText: '页 共 {pages} 页',
displayMsg: '当前显示 {from} - {to} 条记录 共 {total} 条记录'
});
});
public void GetAll(HttpContext context)
{
IList<BelongDepartment> list = bdManage.GetModelList("");
int intPageSize = int.Parse(context.Request["rows"] == null ? "0" : context.Request["rows"]);
int intCurrentPage = int.Parse(context.Request["page"] == null ? "0" : context.Request["page"]);
int totalCount = 0;
string result = DBHelper.GetIEnumberableJson(list, model => model.Id > 0, model => model.Id, intPageSize, intCurrentPage, out totalCount);
context.Response.Write(result);
}
public static string GetIEnumberableJson<T>(IEnumerable<T> List, Func<T, bool> FunWhere, Func<T, int> FunOrder, int PageSize, int PageIndex, out int totalCount)
{
var rance = List.Where(FunWhere);
totalCount = rance.Count();
IList<T> list = rance.OrderBy(FunOrder).Select(t => t).Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList<T>();
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
string result = "{"total":" + totalCount + ", "rows":" + JsonConvert.SerializeObject(list, Formatting.Indented, settings) + "}";
return result;
}
object obj = new { total = total, rows = dt };
string response = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
Response.Write(response);