AspNetPager 的使用
下面选用的是新闻发布系统里用的代码。
SQL 存储过程:
CREATE PROCEDURE procNewsSelectByPager
@startRecordIndex int,
@endRecordIndex int
AS
BEGIN
select * from
(select row_number() over (order by id) as row, * from news) temp
where temp.row between @startRecordIndex and @endRecordIndex
END
GO
数据访问层:
//SQLHelper
public DataTable ExecuteQuery(string cmdText,SqlParameter[] paras,CommandType ct)
{
DataTable dt = new DataTable();
cmd = new SqlCommand(cmdText, Getconn());
cmd.CommandType = ct;
cmd.Parameters.AddRange(paras);
using (sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
dt.Load(sdr);
}
return dt;
} //NewsDAO
public DataTable SelectByPager(int startRecordIndex, int endRecordIndex)
{
DataTable dt = new DataTable();
SqlParameter[] para = new SqlParameter[] {
new SqlParameter("@startRecordIndex",startRecordIndex),
new SqlParameter("@endRecordIndex",endRecordIndex)
};
dt = sqlhelper.ExecuteQuery("procNewsSelectByPager",para, CommandType.StoredProcedure);
return dt;
}
UI层:
<!-- 前台代码 -->
<div>
<table>
<tr><th>ID</th>
<th>新闻标题</th>
</tr>
<asp:Repeater ID="repTest" runat="server">
<ItemTemplate>
<tr>
<td><%# Eval("id") %></td>
<td><a href='../Newscontent.aspx?newsId=<%# Eval("id") %>' target="_blank" title='<%# Eval("title") %>' ><%# StringTruncat(Eval("title").ToString(),21,"...") %></a></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
<webdiyer:AspNetPager ID="anp" FirstPageText="首页" LastPageText="尾页"
PrevPageText="上一页" NextPageText="下一页" SubmitButtonText="Go"
TextBeforePageIndexBox="转到" TextAfterPageIndexBox="页" PageIndexBoxType="TextBox" ShowPageIndexBox="Always"
CustomInfoHTML="共 <font color='#FF0000'>%PageCount%</font> 页,第 <font color='#FF0000'>%CurrentPageIndex%</font> 页"
Font-Size="14px" ShowCustomInfoSection="Left" CustomInfoSectionWidth="25%" PagingButtonSpacing="8px"
runat="server" onpagechanged="anp_PageChanged">
</webdiyer:AspNetPager>
</div>
//后台代码
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
} protected void anp_PageChanged(object sender, EventArgs e)
{
Bind();
} private void Bind()
{
NewsManager nm = new NewsManager();
// 设置需要分页的所有数据的总数
anp.RecordCount = nm.SelectCount();
// 设置 AspNetPager 每页显示的数
anp.PageSize = ;
// 取出当前页的新闻
DataTable dt = nm.SelectByPager(anp.StartRecordIndex, anp.EndRecordIndex);
PagedDataSource pds = new PagedDataSource();
// 设置 页面最多能显示的数量
pds.PageSize = anp.PageSize;
// 是否启用分页
pds.AllowPaging = true;
// 绑定数据源
pds.DataSource = dt.DefaultView;
repTest.DataSource = pds;
repTest.DataBind();
}
关于 AspNetPager 控件的使用:
anp.RecordCount 的设置应在 anp.EndRecordIndex 的使用之前,例:
anp.RecordCount = ;
anp.PageSize = ;
// 自定义的 取出当前页面要显示的数据 的方法
nm.SelectByPager(anp.StartRecordIndex,anp.EndRecordIndex);
AspNetPager 和 PagedDataSource 的 PageSize 属性(每页显示的项数)
当 anp.PageSize < pds.PageSize 时,页面显示的是 anp.PageSize 设置的数;
当 anp.PageSize > pds.PageSize 时,页面显示的是 pds.PageSize 设置的数;
(个人理解)anp.PageSize 是控件每页显示的数,pds.PageSize 是页面最多能显示的数。
AspNetPager 的使用的更多相关文章
- AspNetPager分页控件样式的使用
分页是Web应用程序中最常用到的功能之一,AspNetPager 简单实用,应用到项目后台中,棒极了! 自定义样式: <style type="text/css"> ...
- AspNetPager 多条件分页查询
AspNetPager 这个分页控件一般做后台基本都知道的,我就不多说了(说明与下载链接:http://www.webdiyer.com/Controls/AspNetPager),嘿嘿!其实我也是刚 ...
- AspNetPager分页控件的使用
下面所记得东西仅仅是使用方法,详细知识点请看链接:http://www.webdiyer.com/Controls/AspNetPager/Downloads 首先:从网站上下载并安装控件 下载地址: ...
- AspNetPager分页控件配置
AspNetPager是asp.net中常用的分页控件,下载AspNetPager.dll,添加引用,在工具栏就可以看到AspNetPager控件: 拖过来之后,设置如下属性: <webdiye ...
- 修改AspNetPager的CustomInfoHTML,添加自定义样式
AspNetPager控件有一个属性叫CustomInfoHTML,可以把它写在前台页面,如下: <webdiyer:AspNetPager ID=" HorizontalAlign= ...
- AspNetPager控件分页使用方法
AspNetPager控件官方下载地址:http://www.webdiyer.com/aspnetpager/ 把控件加到项目中(添加自定义控件的方法),并把它拖放到页面上 <asp:Scri ...
- 未能加载文件或程序集“AspNetPager”或它的某一个依赖项。参数错误(转)
未能加载文件或程序集“AspNetPager”或它的某一个依赖项.参数错误. 看你的的开发框架用的是多少的2.0, 3.0, 3.5, 4.0 那么删除的框架的文件夹也相对应的变化 删除 C:\W ...
- AspNetPager控件报错误: Syntax error, unrecognized expression: input#ctl00$ContentPlaceHolder1$Aspnetpager1_input问题解决[摘]
高版本IE,如IE10或者IE11在浏览页面时出现错误: Syntax error, unrecognized expression: input#ctl00$ContentPlaceHolder1$ ...
- 如何使用 aspnetpager
<%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix=" ...
- AspNetPager分页控件
AspNetPager分页控件解决了分页中的很多问题,直接采用该控件进行分页处理,会将繁琐的分页工作变得简单化,下面是我如何使用AspNetPager控件进行分页处理的详细代码:1.首先到www.we ...
随机推荐
- Linux Shell脚本读写XML文件
在Linux下如何用Shell脚本读写XML?现有一个config.xml <?xml version="1.0" encoding="UTF-8"?&g ...
- linux下文件夹的创建、复制、剪切、重命名、清空和删除命令
在home目录下有wwwroot目录,wwwroot下有sinozzz目录,即/home/wwwroot/sinozzz 一.目录创建 在/home/wwwroot目录下新建一个sinozzz123的 ...
- POJ 2409 Let it Bead(polay计数)
题目链接:http://poj.org/problem?id=2409 题意:给出一个长度为m的项链,每个珠子可以用n种颜色涂色.翻转和旋转后相同的算作一种.有多少种不同的项链? 思路: (1) 对于 ...
- [HDOJ2473]Junk-Mail Filter(并查集,删除操作,马甲)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2473 给两个操作:M X Y:将X和Y看成一类. S X:将X单独划归成一类. 最后问的是有多少类. ...
- TCSRM 593 div2(1000)(dp)
Problem Statement The pony Rainbow Dash wants to choose her pet. There are N animals who want t ...
- 设置图片Alpha
Drawable ico = getResources().getDrawable(R.drawable.search_box); mSearchLayou ...
- UVa 1153 Keep the Customer Satisfied 【贪心 优先队列】
题意:给出n个工作,已知每个工作需要的时间last,以及截止时间end,(必须在截止时间之前完成)问最多能够完成多少个工作 首先预处理,将这n件任务按照截止时间从小到大排序 然后用一个cur记录当前做 ...
- POJ 3041 Asteroids (最小点覆盖集)
题意 给出一个N*N的矩阵,有些格子上有障碍,要求每次消除一行或者一列的障碍,最少消除多少次可以全部清除障碍. 思路 把关键点取出来:一个障碍至少需要被它的行或者列中的一个消除. 也许是最近在做二分图 ...
- Nginx - webbench压力测试
1. 下载,安装,进目录. 2. 执行:webbench -t 10 -c 1000 http://192.168.1.44/ (我开的nginx,默认端口80,直接处理了) 结果分析: Webben ...
- FFmpeg介绍及参数详细说明
FFmpeg是一个开源免费跨平台的视频和音频流方案,属于自由软件,采用LGPL或GPL许可证(依据你选择的组件).它提供了录制.转换以及流化音视频的完整解决方案.它包含了非常先进的音频/视频编解码库l ...