分页
来源:互联网 发布:淘宝宝贝数量限制 编辑:程序博客网 时间:2024/06/05 05:55
public partial class Index : System.Web.UI.Page { public static int pageIndex = 1;//初始页码 public int pageSize = 10;//初始页数量 public static int pageCount = 0;//总页数 protected void Page_Load(object sender, EventArgs e) { //获取直接跳转的页号 if (Request["page"] != null) { //判断当前跳转的页数是否大于总页数,如果大于则直接跳转至最后一页 pageIndex = int.Parse(Request["page"].ToString()); if (pageIndex > pageCount) pageIndex = pageCount; else if (pageIndex < 1) pageIndex = 1; LoadGrid(pageSize, pageIndex,ref pageCount); } if (!IsPostBack) { LoadGrid(pageSize, pageIndex, ref pageCount); } } /// <summary> /// 执行分页存储过程 /// </summary> /// <param name="pageSize">页显示数量</param> /// <param name="pageIndex">页码</param> private void LoadGrid(int pageSize,int pageIndex,ref int pageCount) { //string sqlStr = "select * from shop where shopid = @id"; //SqlParameter[] pars = new SqlParameter[]{ // new SqlParameter("@id",56) //}; string sqlStr = "proc_pager"; SqlParameter[] pars = new SqlParameter[] { new SqlParameter("@pageSize",pageSize),//页数量 new SqlParameter("@pageIndex",pageIndex),//页码 new SqlParameter("@pageCount",pageCount)//总页数(输出参数) }; pars[2].Direction = ParameterDirection.Output;//设置参数为输出参数 this.GridView1.DataSource = DBHelper.ExecuteTable(sqlStr, CommandType.StoredProcedure, pars); this.GridView1.DataBind(); pageCount = int.Parse(pars[2].Value.ToString());//将存储过程输出值赋值给pageCount this.lab_PageCount.Text = pageCount.ToString(); //禁用和启用上一页 if (pageIndex == 1) this.first_Hover.Enabled = false; else this.first_Hover.Enabled = true; //禁用和启用下一页 if (pageIndex >= pageCount) this.Last_Hover.Enabled = false; else this.Last_Hover.Enabled = true; } protected void first_Hover_Click(object sender, EventArgs e) { pageIndex--;//当点击上一页时,将页码-1 Response.Redirect("index.aspx?page=" + pageIndex); //LoadGrid(pageSize, pageIndex, ref pageCount); } protected void Last_Hover_Click(object sender, EventArgs e) { pageIndex++;//当点击下一页时,将页码+1 Response.Redirect("index.aspx?page=" + pageIndex); //LoadGrid(pageSize, pageIndex, ref pageCount); } }
数据源分页
public string PageJSON(int row, int page, IList<model> list) { JavaScriptSerializer jss = new JavaScriptSerializer(); int pagecount = list.Count(); var query = list.ToList().Skip(row * (page - 1)).Take(row); return "{\"total\":" + pagecount + ",\"rows\":" + jss.Serialize(query) + "}"; }
阅读全文
0 0
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- DLL如何导出类?
- C++ Primer 第五章 语句
- scikit-learn 实战之非监督学习
- VC获取打印机与打印作业的状态
- 输出某个目录下的所有文件和文件夹,包括子文件夹中的内容
- 分页
- Unicode字符与多字节字符的转换
- VS2010 C++ 操作Excel表格的编程实现
- weblogic stuck thread vs hogger thread
- DLL(动态链接库)
- 回调函数
- 微服务从设计到部署(二)使用 API 网关
- decbin
- 3行核心代码解决汉诺塔问题(C++递归实现)