加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

用PagedDataSource实现分页

发布时间:2020-12-15 04:39:38 所属栏目:百科 来源:网络整理
导读:span style="FONT-SIZE: 10pt"就分页的技术来看,无非是分两种:一。通过存储过程来实现???? 此点,暂时不讲,因为网上文章很多,迟一下再发表我的意见。二。通过页面代码来实现??? 我之前在网上看到一个文章,说的是为DATALIST分页,用的技术是viewstate保

<span style="FONT-SIZE: 10pt">就分页的技术来看,无非是分两种:一。通过存储过程来实现???? 此点,暂时不讲,因为网上文章很多,迟一下再发表我的意见。二。通过页面代码来实现??? 我之前在网上看到一个文章,说的是为DATALIST分页,用的技术是viewstate保存分页信息,然后再通过这个信息(如当前是第几页,每页多少等)来实现分页。虽然能实现功能,不过,这一点明显是多此一举,究其原因,是由于没有深入认识。NET。其实。NET本身有一个PagedDataSource,它是从GridView里分离出来的分页代码封装,可以轻松实现分页。下面,就以DATALIST作为例子,看一下,他是怎样使用的:<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">???????<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">以上代码省略<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">?DataSet?ds?=?db.ExecuteDataSet(dbc);<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????PagedDataSource?pds?=?new?PagedDataSource();//初始化分页源<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????pds.DataSource?=?ds.Tables[0].DefaultView;<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????pds.PageSize?=?15;//每页显示的记录数<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????pds.AllowPaging?=?true;//是否分页<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????pds.CurrentPageIndex?=?pageid?-?1;//当前页数,因为从0开始,所以接收到的数减1<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????DataList1.DataSource?=?pds;//绑定数据源<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????DataList1.DataBind();//绑定数据<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????if?(pds.IsFirstPage)<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????????hy1.Visible?=?false;<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????if?(pds.IsLastPage)<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????????hy2.Visible?=?false;<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????int?pg;<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????int?showp?=?10;//显示多少页<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">???????<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????string?pgstr;<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????pgstr?=?"?";//分页显示代码<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????int?startp;//开始页数<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????int?nowp;<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????nowp?=?pds.CurrentPageIndex?+?1;<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????int?totalp;<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????totalp?=?pds.PageCount;//得到总页数<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????//???startp?=?1;<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/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.52php.cn/res/2019/03-05/01/405b18b4b6584ae338e0f6ecaf736533.gif" align="top"><img id="Codehighlighter1_844_1052_Closed_Image" onclick="code_collapse_toggle(this);" src="https://www.52php.cn/res/2019/03-05/01/1c53668bcee393edac0d7b3b3daff1ae.gif" align="top">????????<img src="https://www.52php.cn/res/2019/03-05/01/a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif"&gt;{<img src="https://www.52php.cn/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top">????????????startp?=?pds.CurrentPageIndex?+?2;<img src="https://www.52php.cn/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"><img src="https://www.52php.cn/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.52php.cn/res/2019/03-05/01/2887d91d0594ef8793c1db92b8a1d545.gif" align="top"><img id="Codehighlighter1_945_995_Closed_Image" onclick="code_collapse_toggle(this);" src="https://www.52php.cn/res/2019/03-05/01/7a2b9a960ee9a98bfd25d306d55009f8.gif" align="top">????????????<img src="https://www.52php.cn/res/2019/03-05/01/a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif"&gt;{<img src="https://www.52php.cn/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top">????????????????pg?=?(nowp+showp);<img src="https://www.52php.cn/res/2019/03-05/01/105a1e124122b2abcee4ea8e9f5108f3.gif" align="top">????????????}<img src="https://www.52php.cn/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top">????????????else<img src="https://www.52php.cn/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top">????????????????pg?=?totalp;<img src="https://www.52php.cn/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/05dd8d549cff04457a6366b0a7c9352a.gif" align="top">????????}<img src="https://www.52php.cn/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.52php.cn/res/2019/03-05/01/405b18b4b6584ae338e0f6ecaf736533.gif" align="top"><img id="Codehighlighter1_1075_1181_Closed_Image" onclick="code_collapse_toggle(this);" src="https://www.52php.cn/res/2019/03-05/01/1c53668bcee393edac0d7b3b3daff1ae.gif" align="top">????????<img src="https://www.52php.cn/res/2019/03-05/01/a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif"&gt;{<img src="https://www.52php.cn/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top">????????????startp?=?Convert.ToInt16((nowp)?/?showp)?*?showp;<img src="https://www.52php.cn/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top">????????????pg?=?startp?+?showp;<img src="https://www.52php.cn/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/05dd8d549cff04457a6366b0a7c9352a.gif" align="top">????????}<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/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.52php.cn/res/2019/03-05/01/405b18b4b6584ae338e0f6ecaf736533.gif" align="top"><img id="Codehighlighter1_1218_1276_Closed_Image" onclick="code_collapse_toggle(this);" src="https://www.52php.cn/res/2019/03-05/01/1c53668bcee393edac0d7b3b3daff1ae.gif" align="top">????????<img src="https://www.52php.cn/res/2019/03-05/01/a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif"&gt;{<img src="https://www.52php.cn/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top">????????????pg?=?showp;<img src="https://www.52php.cn/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top">????????????startp?=?1;<img src="https://www.52php.cn/res/2019/03-05/01/05dd8d549cff04457a6366b0a7c9352a.gif" align="top">????????}<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">??????//??Response.Write(pg);<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">??????//??Response.End();<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/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.52php.cn/res/2019/03-05/01/405b18b4b6584ae338e0f6ecaf736533.gif" align="top"><img id="Codehighlighter1_1406_1692_Closed_Image" onclick="code_collapse_toggle(this);" src="https://www.52php.cn/res/2019/03-05/01/1c53668bcee393edac0d7b3b3daff1ae.gif" align="top">????????<img src="https://www.52php.cn/res/2019/03-05/01/a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif"&gt;{<img src="https://www.52php.cn/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top">????????????if?((nowp)?==?p)<img src="https://www.52php.cn/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top">????????????????pgstr?=?pgstr?+?"????"?+?p;<img src="https://www.52php.cn/res/2019/03-05/01/33d02437d135341f0800e3d415312ae8.gif" align="top">????????????else<img src="https://www.52php.cn/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.52php.cn/res/2019/03-05/01/05dd8d549cff04457a6366b0a7c9352a.gif" align="top">????????}<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????fromto.Text?=?pgstr;<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????//??hy1.Text=Request.CurrentExecutionFilePath+"?pageIndex="+Convert.ToString(CurrentPage+1);?<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/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.52php.cn/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.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">????????Label1.Text?=?Convert.ToString(pds.PageCount);<img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top"><img src="https://www.52php.cn/res/2019/03-05/01/a6339ee3e57d1d52bc7d02b338e15a60.gif" align="top">以下代码省略

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读