public int OverPage() { int pages = 0; if(RecCount%PageSize != 0) pages = 1; else pages = 0; return pages; } //计算余页,防止SQL语句执行时溢出查询范围 public int ModPage() { int pages = 0; if(RecCount%PageSize == 0 && RecCount != 0) pages = 1; else pages = 0; return pages; } /* *计算总记录的静态函数 *本人在这里使用静态函数的理由是:如果引用的是静态数据或静态函数,连接器会优化生成代码,去掉动态重定位项(对
海量数据表分页效果更明显)。 *希望大家给予意见、如有不正确的地方望指正。 */ public static int Calc() { int RecordCount = 0; SqlCommand MyCmd = new SqlCommand("select count(*) as co from redheadedfile",MyCon()); SqlDataReader dr = MyCmd.ExecuteReader(); if(dr.Read()) RecordCount = Int32.Parse(dr["co"].ToString()); MyCmd.Connection.Close(); return RecordCount; } //数据库连接语句(从Web.Config中获取) public static SqlConnection MyCon() { SqlConnection MyConnection = new SqlConnection(ConfigurationSettings.AppSettings["DSN"]); MyConnection.Open(); return MyConnection; } //对四个按钮(首页、上一页、下一页、尾页)返回的CommandName值进行操作 private void Page_OnClick(object sender, CommandEventArgs e) { CurrentPage = (int)ViewState["PageIndex"];//从ViewState中读取页码值保存到CurrentPage变量中进行参数运
算 Pages = (int)ViewState["PageCounts"];//从ViewState中读取总页参数运算
string cmd = e.CommandName; switch(cmd)//筛选CommandName { case "next": CurrentPage++; break; case "prev": CurrentPage--; break; case "last": CurrentPage = Pages; break; default: CurrentPage = 0;
上一篇:asp.net(C#)海量数据表高效率分页算法(易懂,不使用存储过程)
下一篇:php+xapian extension的安装
|