jQuery MiniUI

 找回密码
 立即注册
查看: 3007|回复: 3
打印 上一主题 下一主题

【原创】翻页asp.net实现方法 [复制链接]

Rank: 1

跳转到指定楼层
楼主
发表于 2012-12-13 14:20:13 |只看该作者 |倒序浏览
  1. /// <summary>
  2. /// 翻页查询目标表数据
  3. /// </summary>
  4. /// <param name="table">表名(支持构造表)</param>
  5. /// <param name="key">主键</param>
  6. /// <param name="flds">查询字段</param>
  7. /// <param name="where">筛选(需要加where)</param>
  8. /// <param name="sort">排序字段</param>
  9. /// <param name="order">排序类型</param>
  10. /// <param name="index">页码(从一开始)</param>
  11. /// <param name="size">页大小</param>
  12. /// <returns>数据集</returns>
  13. public Hashtable GetDataSet(string table,string key,string flds,string where,string sort,string order,int index,int size)
  14. {
  15. string sql = "";
  16. string orderby = "";
  17. if (!string.IsNullOrEmpty(sort))
  18. {
  19. if (order != "desc") order = "asc";
  20. orderby = " order by " + sort + " " + order;
  21. }
  22. else
  23. {
  24. if (order != "desc") order = "asc";
  25. orderby = " order by " + key + " " + order;
  26. }
  27. sql = string.Format(@"select {0} from {1} where {3} in(
  28. select top ({5}) {3} from(select row_number()over({4}) as rownum,{3} from {1} {2}) as Tb
  29. where rownum>(({6}-1)*{5})) {4}
  30. select count(*) as total from {1} {2}",flds,table,where,key,orderby,size,index);

  31. DataSet ds = Sqlhelper.GetDataSet(Sqlhelper.connectionString, CommandType.Text, sql);
  32. if (ds != null)
  33. {
  34. if (ds.Tables.Count == 2)
  35. {
  36. DataTable dt = ds.Tables[0];
  37. ArrayList data = this.DataTable2ArrayList(dt);
  38. Hashtable result = new Hashtable();
  39. result["data"] = data;
  40. result["total"] = ds.Tables[1].Rows[0][0].ToString();
  41. return result;
  42. }
  43. }
  44. return null;
  45. }

  46. private ArrayList DataTable2ArrayList(DataTable data)
  47. {
  48. ArrayList array = new ArrayList();
  49. for (int i = 0; i < data.Rows.Count; i++)
  50. {
  51. DataRow row = data.Rows[i];

  52. Hashtable record = new Hashtable();
  53. for (int j = 0; j < data.Columns.Count; j++)
  54. {
  55. object cellValue = row[j];
  56. if (cellValue.GetType() == typeof(DBNull))
  57. {
  58. cellValue = null;
  59. }
  60. record[data.Columns[j].ColumnName] = cellValue;
  61. }
  62. array.Add(record);
  63. }
  64. return array;
  65. }
复制代码
在miniui提供的.net后台代码上写的一个翻页的实现方法。

Rank: 9Rank: 9Rank: 9

沙发
发表于 2012-12-13 21:03:29 |只看该作者
MiniUI默认就是ajax无刷新分页。
你也可以自己做一个分页控件,获取JS数组后:
grid.setData(data);

Rank: 3Rank: 3

板凳
发表于 2012-12-19 22:03:17 |只看该作者
本帖最后由 johnconner 于 2012-12-19 22:07 编辑

27.sql = string.Format(@"select {0} from {1} where {3} in(

28.select top ({5}) {3} from(select row_number()over({4}) as rownum,{3} from {1} {2}) as Tb

29.where rownum>(({6}-1)*{5})) {4}

30.select count(*) as total from {1} {2}",flds,table,where,key,orderby,size,index);

你好,不好意思,请教一下,我从来没见过这种写法,这些{0},{3},{5}这种在大括号里的数字是什么意思?是GetDataSet方法参数的调用吗?请赐教!谢谢!

明白了,是对应后面变量的索引,对吗?

Rank: 9Rank: 9Rank: 9

地板
发表于 2012-12-20 14:17:07 |只看该作者
这个是此用户自己的SQL语句字符串拼接方法,跟MiniUI没任何关系。。。

Archiver|普加软件

GMT+8, 2024-11-25 03:07 , Processed in 1.044933 second(s), 9 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部