版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、分页所需的存储过程(这里没有加条件,可自行添加,用时加上参数即可)create procedure Base_Page Page_Num int, -当前的页数。 Page_Size int, -每页显示的 Table_Name varchar(100), -要操作的表名Sort_Name varchar(100), -排序字段名,默认为'0'Sort_Type varchar(20) -排序方式,默认为'0'as - 执行SQL语句,除了所有数据外,还返回总页数。declare Temp_StrA as varchar(300) -备用组合字符串Adeclar
2、e Temp_StrB as varchar(300) -备用组合字符串Bif Page_Num >=1 begin-因之后的分页必须要求有排序,暂时给它默认的排序方式为NewID()set Temp_StrA = ' order by NewID() desc 'if Sort_Name <> '0'beginif Sort_Type <> '0'beginset Temp_StrA = ' order by ' + Sort_Name + ' ' + Sort_Typeendels
3、ebeginset Temp_StrA = ' order by ' + Sort_Name + ' desc'endendset Temp_StrB = 'select * from (select count(*) over() as RowNum ,Row_Number() over ('+ Temp_StrA +') as RowIndex ,* from '+ Table_Name +' ) as NewTitle where NewTitle.RowIndex > ('+ convert(varc
4、har(10),Page_Num) +' - 1) * '+ convert(varchar(10),Page_Size) +') and NewTitle.RowIndex <= ('+ convert(varchar(10),Page_Num) +' * '+ convert(varchar(10),Page_Size) +')'execute(Temp_StrB) -提交执行end分页按钮所需的样式.PageListwidth:100%;font-size:12px;padding-top:15px;position:
5、relative;padding-bottom:15px;.PageList amargin-left:3px;margin-right:3px;text-decoration: none;padding:4px 8px 4px 8px;border:1px solid #dddddd;.PageList a:link,.PageList a:visited color:#999999;.PageList a:hover color:#ff9000;background:#fff7e2;border:1px solid #ff7300;.ThisPage:link,.ThisPage:visi
6、tedcolor:#656565;border:1px solid #a2d2ff;background:#f2f9ff;.PageCode:link,.PageCode:visitedbackground:#f3f3f3;分页完整类代码(详细的注释可直接复制)using System;using System.Data;using System.Configuration;using System.Data.SqlClient;using System.Linq;using System.Text;using System.Web;using System.Web.Security;usin
7、g System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;/ <summary>/The_Page 的摘要说明/ </summary>public class The_Page protected int RowNum;/总共的数据条数 protected int PageNum = 1;/默认页数 protected int PageAll
8、= 1;/总共多少页 protected int PageSize = 20;/默认每页的条数 protected int ThisPageShow = 5;/默认显示页数的按钮数 protected string PageName = string.Empty;/标的名称或是视图的名称 protected string SortName = "0"/数据的排序方式 protected string SortType = "0"/排序的方式 protected string ThisUrl = string.Empty;/请求的页面的路径 protect
9、ed StringBuilder PageList = new StringBuilder();/向前台发送的全部字符串 public DataSet PageTable = new DataSet();/当页数据的集合,执行完分页方法后才能得到值(前台获得这个集合后可以再去插入IList进行操作) / <summary> / 生成分页的按钮集合(有存储过程配合,存储过程暂时没有加入条件,加入的时候再加上一个参数即可,切记CSS样式) / </summary> / <param name="con">数据链接对象</param>
10、; / <param name="pagenum">当前页数(注:输入整型,如果不是则返回默认页)</param> / <param name="pagesize">每页显示的数据条数(注:输入整型,如果不是则返回默认页)</param> / <param name="pagename">要操作的表明或者视图</param> / <param name="sortname">排列字段,可为null,存储过程的默认值为“0”,含义是随
11、机排列</param> / <param name="sorttype">排序方式,可为null,存储过程的默认值为“0”,含义是“desc”降序排列</param> / <param name="thispageshow">控件上显示的页数的按钮的数量,默认值为5个</param> / <param name="thisurl">当页的Url,用来组合字符串</param> / <returns></returns> publ
12、ic string GetPageList(SqlConnection con, string pagenum, string pagesize, string pagename, string sortname, string sorttype, int thispageshow, string thisurl) #region 传入值的判断 if (JudgeInt(pagenum) if (Convert.ToInt32(pagenum) > 0)/输入的为浮点数的话按强制转换的值为准 PageNum = Convert.ToInt32(pagenum); if (JudgeInt
13、(pagesize) if (Convert.ToInt32(pagesize) > 0)/输入的为浮点数的话按强制转换的值为准 PageSize = Convert.ToInt32(pagesize); PageName = pagename; if (!string.IsNullOrEmpty(sortname.Trim() SortName = sortname; if (!string.IsNullOrEmpty(sorttype.Trim() SortType = sorttype; if (thispageshow > 0) ThisPageShow = thispag
14、eshow; CountPageAll(con); #endregion #region 获取数据,这里可以根据项目修改使用的方法 con.Open();/打开连接 SqlDataAdapter sdr = new SqlDataAdapter(); SqlCommand com = new SqlCommand("Base_Page", con); com.CommandType = CommandType.StoredProcedure; com.Parameters.Add("Page_Num", SqlDbType.Int); com.Param
15、eters"Page_Num".Value = PageNum; com.Parameters.Add("Page_Size", SqlDbType.Int); com.Parameters"Page_Size".Value = PageSize; com.Parameters.Add("Table_Name", SqlDbType.VarChar); com.Parameters"Table_Name".Value = PageName; com.Parameters.Add("So
16、rt_Name", SqlDbType.VarChar); com.Parameters"Sort_Name".Value = SortName; com.Parameters.Add("Sort_Type", SqlDbType.VarChar); com.Parameters"Sort_Type".Value = SortType; com.ExecuteNonQuery(); con.Close();/关闭连接 sdr.SelectCommand = com; sdr.Fill(PageTable, "se&
17、quot;); #endregion #region 组合成分页的字符串,样式单独去定义 PageList.Append("<div class="PageList">"); if (PageTable.Tables.Count > 0) if (PageTable.Tables0.Rows.Count > 0) ListItme(thisurl); else PageList.Append("<div class="NoThing">没有找到任何一条记录!</div>&quo
18、t;); else PageList.Append("<div class="NoThing">没有找到任何一条记录!</div>"); PageList.Append("</div>"); #endregion) return PageList.ToString(); / <summary> / 组合字符串 / </summary> protected void ListItme(string url) #region 需要的参数 int pageNumtemp = Pag
19、eAll / ThisPageShow;/取小数的整数部分(用于列表组) int numOthertemp = PageAll % ThisPageShow;/取余(用于列表组) int lastTemp;/上一组按钮列最后一个按钮值(必须在有存在上组列时用) int nextTemp;/下一组按钮列第一个按钮值(必须在有存在下组列时用) int lastpageNumtemp = PageNum / ThisPageShow;/取小数的整数部分(用于按钮组) int nextnumOthertemp = PageNum % ThisPageShow;/取余(用于按钮组) /计算上组按钮,值必
20、须大于0,不然就是不存在上组 if (nextnumOthertemp = 0) lastTemp = (lastpageNumtemp - 1) * ThisPageShow; else lastTemp = lastpageNumtemp * ThisPageShow; /计算下组按钮,值必须小于等于PageAll,不然不存在下组 if (nextnumOthertemp = 0) nextTemp = (lastpageNumtemp * ThisPageShow) + 1; else nextTemp = (lastpageNumtemp + 1) * ThisPageShow) +
21、1; #endregion #region 处理url int sta = url.ToLower().IndexOf("aspx?");/判断地址有没有参数传递 if (sta > 0) /分成两个判断的原因是,如果直接判断“page=”这样一旦出现这样的参数“sizepage=”会引起逻辑错误 int stb = url.ToLower().IndexOf("&page=");/判断有没有分页参数传递(不是第一个参数的情况) int stc = url.ToLower().IndexOf("?page=");/判断有
22、没有分页参数传递(是第一个参数的情况) if (stb > 0 | stc > 0) if (stb > 0) int std = url.ToLower().Substring(stb + 1, url.Length - (stb + 1).IndexOf('&'); if (std > 0)/后面还有参数 string ste = url.ToLower().Substring(stb + 1) + std);/这个字符串前面带“&” ThisUrl = url.ToLower().Substring(0, stb) + ste +
23、"&Page=" else ThisUrl = url.ToLower().Substring(0, stb) + "&Page=" if (stc > 0) int std = url.ToLower().IndexOf("&"); if (std > 0)/后面还有参数 string ste = url.ToLower().Substring(std + 1);/这个字符串前面去掉了“&” ThisUrl = url.ToLower().Substring(0, stc + 1) + s
24、te + "&Page=" else ThisUrl = url.ToLower().Substring(0, stc) + "?Page=" else ThisUrl = url + "&Page=" else ThisUrl = url + "?Page=" #endregion /只有一页的情况) if (PageAll = 1) PageList.Append("<a href="" + ThisUrl + "1" class=&quo
25、t;ThisPage" title="第1页">1</a>"); else /总页数大于一页时,访问第一页的情况 if (PageNum = 1) #region 当页数是1页的时候 /总共的页数大于每页要显示的按钮数 if (pageNumtemp > 1) for (int i = 1; i <= ThisPageShow; i+) if (i = 1) PageList.Append("<a href="" + ThisUrl + i + "" class=&qu
26、ot;ThisPage" title="第" + i + "页">" + i + "</a>"); else PageList.Append("<a href="" + ThisUrl + i + "" title="第" + i + "页">" + i + "</a>"); PageList.Append("<a href="&
27、quot; + ThisUrl + (ThisPageShow + 1) + "" class="PageCode" title="后" + ThisPageShow + "页">.</a>"); PageList.Append("<a href="" + ThisUrl + (PageNum + 1) + "" class="PageCode" title="下一页">><
28、/a>"); PageList.Append("<a href="" + ThisUrl + PageAll + "" class="PageCode" title="末页">>></a>"); else if (pageNumtemp = 1) if (numOthertemp = 0) for (int i = 1; i <= PageAll; i+) if (i = 1) PageList.Append("<a hr
29、ef="" + ThisUrl + i + "" class="ThisPage" title="第" + i + "页">" + i + "</a>"); else PageList.Append("<a href="" + ThisUrl + i + "" title="第" + i + "页">" + i + "</
30、a>"); PageList.Append("<a href="" + ThisUrl + (PageNum + 1) + "" class="PageCode" title="下一页">></a>"); else for (int i = 1; i <= ThisPageShow; i+) if (i = 1) PageList.Append("<a href="" + ThisUrl + i + &quo
31、t;" class="ThisPage" title="第" + i + "页">" + i + "</a>"); else PageList.Append("<a href="" + ThisUrl + i + "" title="第" + i + "页">" + i + "</a>"); PageList.Append("
32、<a href="" + ThisUrl + (ThisPageShow + 1) + "" class="PageCode" title="后" + ThisPageShow + "页">.</a>"); PageList.Append("<a href="" + ThisUrl + (PageNum + 1) + "" class="PageCode" title="下一页
33、">></a>"); PageList.Append("<a href="" + ThisUrl + PageAll + "" class="PageCode" title="末页">>></a>"); else for (int i = 1; i <= PageAll; i+) if (i = 1) PageList.Append("<a href="" + ThisUrl
34、 + i + "" class="ThisPage" title="第" + i + "页">" + i + "</a>"); else PageList.Append("<a href="" + ThisUrl + i + "" title="第" + i + "页">" + i + "</a>"); PageList.Ap
35、pend("<a href="" + ThisUrl + (PageNum + 1) + "" class="PageCode" title="下一页">></a>"); #endregion else /最后一页时的情况 if (PageAll = PageNum) #region 当页数是最后一页的情况 /总共的页数大于每页要显示的按钮数 if (pageNumtemp > 1) PageList.Append("<a href="
36、;" + ThisUrl + "1" + "" class="PageCode" title="首页"><<</a>"); PageList.Append("<a href="" + ThisUrl + (PageNum - 1) + "" class="PageCode" title="上一页"><</a>"); PageList.Ap
37、pend("<a href="" + ThisUrl + lastTemp + "" class="PageCode" title="前" + ThisPageShow + "页">.</a>"); for (int i = lastTemp + 1; i <= PageAll; i+) if (i = PageAll) PageList.Append("<a href="" + ThisUrl + i + &
38、quot;" class="ThisPage" title="第" + i + "页">" + i + "</a>"); else PageList.Append("<a href="" + ThisUrl + i + "" title="第" + i + "页">" + i + "</a>"); else if (pageNumtem
39、p = 1) if (numOthertemp = 0) PageList.Append("<a href="" + ThisUrl + (PageNum - 1) + "" class="PageCode" title="上一页"><</a>"); for (int i = 1; i <= PageAll; i+) if (i = PageNum) PageList.Append("<a href="" + ThisUrl
40、 + i + "" class="ThisPage" title="第" + i + "页">" + i + "</a>"); else PageList.Append("<a href="" + ThisUrl + i + "" title="第" + i + "页">" + i + "</a>"); else PageLi
41、st.Append("<a href="" + ThisUrl + "1" + "" class="PageCode" title="首页"><<</a>"); PageList.Append("<a href="" + ThisUrl + (PageNum - 1) + "" class="PageCode" title="上一页">&l
42、t;</a>"); PageList.Append("<a href="" + ThisUrl + lastTemp + "" class="PageCode" title="前" + ThisPageShow + "页">.</a>"); for (int i = lastTemp + 1; i <= PageAll; i+) if (i = PageAll) PageList.Append("<a hre
43、f="" + ThisUrl + i + "" class="ThisPage" title="第" + i + "页">" + i + "</a>"); else PageList.Append("<a href="" + ThisUrl + i + "" title="第" + i + "页">" + i + "</a
44、>"); else PageList.Append("<a href="" + ThisUrl + (PageNum - 1) + "" class="PageCode" title="上一页"><</a>"); for (int i = 1; i <= PageAll; i+) if (i = PageNum) PageList.Append("<a href="" + ThisUrl + i + &quo
45、t;" class="ThisPage" title="第" + i + "页">" + i + "</a>"); else PageList.Append("<a href="" + ThisUrl + i + "" title="第" + i + "页">" + i + "</a>"); #endregion else #region 除了第一页和最后一页的情况 /总共的页数大于每页要显示的按钮数 if
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年大连装备制造职业技术学院单招职业技能测试题库带答案详解(考试直接用)
- 2026年安庆师范大学单招职业技能考试题库及答案详解(名校卷)
- 2026年天府新区航空旅游职业学院单招职业技能考试题库含答案详解(培优b卷)
- 2026年宁夏工商职业技术学院单招职业适应性考试题库有答案详解
- 2026年安徽工商职业学院单招职业倾向性测试题库及参考答案详解一套
- 2026年安徽工商职业学院单招职业倾向性考试题库含答案详解(精练)
- 2026年安徽工商职业学院单招职业技能考试题库附答案详解(a卷)
- 2026年安徽工商职业学院单招职业适应性考试题库及1套完整答案详解
- 2026年安徽工贸职业技术学院单招综合素质考试题库及答案详解(必刷)
- 2026年安徽工贸职业技术学院单招职业倾向性测试题库含答案详解(综合卷)
- 2024年山东烟台高三一模语文试题答案详解讲评课件
- 小学劳动四年级全册教案
- 牧草栽培学课件
- 中西医结合治疗精神病
- 中国船级社CCS规范指南-《船舶网络安全指南》(2023年)
- 双光子显微镜在生物医学中的应用及其进展
- 血液透析血管通路的感染与预防
- 220324-员工手册民主程序步骤及相应签字文件
- 鼎川建筑设计二层别墅鼎川别墅图纸
- 小型冷藏库制冷设计方案
- 2023年医技类-卫生检验技术(师)代码:211考试历年真题集锦含答案
评论
0/150
提交评论