<span >就分页的技术来看,无非是分两种:一。通过存储过程来实现 此点,暂时不讲,因为网上文章很多,迟一下再发表我的意见。二。通过页面代码来实现 我之前在网上看到一个文章,说的是为DATAList分页,用的技术是vIEwstate保存分页信息,然后再通过这个信息(如当前是第几页,每页多少等)来实现分页。虽然能实现功能,不过,这一点明显是多此一举,究其原因,是由于没有深入认识。NET。其实。NET本身有一个PagedDataSource,它是从GrIDVIEw里分离出来的分页代码封装,可以轻松实现分页。下面,就以DATAList作为例子,看一下,他是怎样使用的:<div >
<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> <img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">以上代码省略<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> DataSet ds = db.ExecuteDataSet(dbc);<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> PagedDataSource pds = new PagedDataSource();//初始化分页源<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> pds.DataSource = ds.tables[0].defaultview;<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> pds.PageSize = 15;//每页显示的记录数<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> <img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> pds.AllowPaging = true;//是否分页<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> pds.CurrentPageIndex = pageID - 1;//当前页数,因为从0开始,所以接收到的数减1<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> DataList1.DataSource = pds;//绑定数据源<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> DataList1.DataBind();//绑定数据<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> if (pds.IsFirstPage)<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> hy1.Visible = false;<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> if (pds.IsLastPage)<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> hy2.Visible = false;<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> int pg;<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> int showp = 10;//显示多少页<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> <img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> string pgstr;<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> pgstr = " ";//分页显示代码<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> int startp;//开始页数<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> int Nowp;<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> Nowp = pds.CurrentPageIndex + 1;<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> int totalp;<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> totalp = pds.PageCount;//得到总页数<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> // startp = 1;<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> if (Nowp % showp == 0)//是否等于上限<img ID="CodeHighlighter1_844_1052_Open_Image" onclick="code_collapse_toggle(this);" src="https://www.jb51.cc/res/2019/03-05/01/405b18b4b6584ae338e0f6ecaf736533.gif" align="top"><img ID="CodeHighlighter1_844_1052_Closed_Image" onclick="code_collapse_toggle(this);" src="https://www.jb51.cc/res/2019/03-05/01/1c53668bcee393edac0d7b3b3daff1ae.gif" align="top"> <img src="https://www.jb51.cc/res/2019/03-05/01/a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif">{<img src="https://www.jb51.cc/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"> startp = pds.CurrentPageIndex + 2;<img src="https://www.jb51.cc/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"> if (totalp > (Nowp+showp))<img ID="CodeHighlighter1_945_995_Open_Image" onclick="code_collapse_toggle(this);" src="https://www.jb51.cc/res/2019/03-05/01/2887d91d0594ef8793c1db92b8a1d545.gif" align="top"><img ID="CodeHighlighter1_945_995_Closed_Image" onclick="code_collapse_toggle(this);" src="https://www.jb51.cc/res/2019/03-05/01/7a2b9a960ee9a98bfd25d306d55009f8.gif" align="top"> <img src="https://www.jb51.cc/res/2019/03-05/01/a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif">{<img src="https://www.jb51.cc/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"> pg = (Nowp+showp);<img src="https://www.jb51.cc/res/2019/03-05/01/105a1e124122b2abcee4ea8e9f5108f3.gif" align="top"> }<img src="https://www.jb51.cc/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"> else<img src="https://www.jb51.cc/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"> pg = totalp;<img src="https://www.jb51.cc/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/05dd8d549cff04457a6366b0a7c9352a.gif" align="top"> }<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> else<img ID="CodeHighlighter1_1075_1181_Open_Image" onclick="code_collapse_toggle(this);" src="https://www.jb51.cc/res/2019/03-05/01/405b18b4b6584ae338e0f6ecaf736533.gif" align="top"><img ID="CodeHighlighter1_1075_1181_Closed_Image" onclick="code_collapse_toggle(this);" src="https://www.jb51.cc/res/2019/03-05/01/1c53668bcee393edac0d7b3b3daff1ae.gif" align="top"> <img src="https://www.jb51.cc/res/2019/03-05/01/a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif">{<img src="https://www.jb51.cc/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"> startp = Convert.ToInt16((Nowp) / showp) * showp;<img src="https://www.jb51.cc/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"> pg = startp + showp;<img src="https://www.jb51.cc/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/05dd8d549cff04457a6366b0a7c9352a.gif" align="top"> }<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> if (startp == 0)<img ID="CodeHighlighter1_1218_1276_Open_Image" onclick="code_collapse_toggle(this);" src="https://www.jb51.cc/res/2019/03-05/01/405b18b4b6584ae338e0f6ecaf736533.gif" align="top"><img ID="CodeHighlighter1_1218_1276_Closed_Image" onclick="code_collapse_toggle(this);" src="https://www.jb51.cc/res/2019/03-05/01/1c53668bcee393edac0d7b3b3daff1ae.gif" align="top"> <img src="https://www.jb51.cc/res/2019/03-05/01/a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif">{<img src="https://www.jb51.cc/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"> pg = showp;<img src="https://www.jb51.cc/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"> startp = 1;<img src="https://www.jb51.cc/res/2019/03-05/01/05dd8d549cff04457a6366b0a7c9352a.gif" align="top"> }<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> // Response.Write(pg);<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> // Response.End();<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> for (int p = startp; p <= pg; p++)//循环显示页数,并生成相应的URL<img ID="CodeHighlighter1_1406_1692_Open_Image" onclick="code_collapse_toggle(this);" src="https://www.jb51.cc/res/2019/03-05/01/405b18b4b6584ae338e0f6ecaf736533.gif" align="top"><img ID="CodeHighlighter1_1406_1692_Closed_Image" onclick="code_collapse_toggle(this);" src="https://www.jb51.cc/res/2019/03-05/01/1c53668bcee393edac0d7b3b3daff1ae.gif" align="top"> <img src="https://www.jb51.cc/res/2019/03-05/01/a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif">{<img src="https://www.jb51.cc/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"> if ((Nowp) == p)<img src="https://www.jb51.cc/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"> pgstr = pgstr + " " + p;<img src="https://www.jb51.cc/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"> else<img src="https://www.jb51.cc/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"> pgstr = pgstr + " <a href=\"" + Request.CurrentExecutionfilePath + "?PageID=" + Convert.ToString(p) + "&RootID=" + Convert.ToString(root_ID) + "\">" + (p) + "";<img src="https://www.jb51.cc/res/2019/03-05/01/05dd8d549cff04457a6366b0a7c9352a.gif" align="top"> }<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> fromto.Text = pgstr;<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> // hy1.Text=Request.CurrentExecutionfilePath+"?pageIndex="+Convert.ToString(CurrentPage+1); <img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> hy1.NavigateUrl = Request.CurrentExecutionfilePath + "?PageID=" + Convert.ToString(pageID - 1) + "&RootID=" + Convert.ToString(root_ID);<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> hy2.NavigateUrl = Request.CurrentExecutionfilePath + "?PageID=" + Convert.ToString(pageID + 1) + "&RootID=" + Convert.ToString(root_ID);<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"> Label1.Text = Convert.ToString(pds.PageCount);<img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.jb51.cc/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">以下代码省略
以上是内存溢出为你收集整理的用PagedDataSource实现分页全部内容,希望文章能够帮你解决用PagedDataSource实现分页所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)