/// <summary> /// 将数据源转换为JQGRID的JSON格式 /// </summary> /// <typeparam name="T">数据类型</typeparam> /// <param name="pageindex">页索引</param> /// <param name="pagesize">页尺寸</param> /// <param name="list">数据源</param> /// <returns></returns> public static string ConvertTojQgridJSON <T>(int pageindex, int pagesize, IList <T> list) { int recordcount = list.Count; int pagecount = SqlEasy.GetDataPages(pagesize, recordcount); IList <T> _list = list.Skip <T>((pageindex - 1) * pagesize).Take <T>(pagesize).ToList <T>(); string json = FormatJSONForJQgrid(pagecount, pageindex, recordcount, _list); return(json); }
/// <summary> /// 获取指定表的数据,并转换为jqgrid 的JSON格式。适用于sql2000 以上版本 /// </summary> /// <param name="fields">要选取的列,以逗号隔开</param> /// <param name="pageindex">当前第几页</param> /// <param name="pagesize">每页记录条数</param> /// <param name="orderfield">排序</param> /// <param name="key">关键字</param> /// <param name="where">条件</param> /// <param name="tbname">表名或视图名</param> /// <returns></returns> public static string GetJsonforjQgrid(string fields, int pageindex, int pagesize, string orderfield, string key, string where, string tbname) { int recordcount = 0; DataTable dt = SqlEasy.GetDataByPager2000(fields, tbname, where, orderfield, key, pageindex, pagesize, out recordcount); int pagecount = SqlEasy.GetDataPages(pagesize, recordcount); string json = FormatJSONForJQgrid(pagecount, pageindex, recordcount, dt); return(json); }