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 ...
随机推荐
- Android 清除canvas 笔迹代码
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); canvas.drawLine(pointX, , event.getX(), ...
- MongoDB 安装和即基本操作
http://www.mongodb.org/ Agile and Scalable MongoDB (from "humongous") is an open-source do ...
- php整理(一):变量和字符串
PHP中的变量: 1. 定义:$符号来定义变量 2. 说明: (1)PHP弱语言,定义变量的时候不用声明类型,但是并不代表PHP没有数据类型 (2)变量名是区分大小写的,只能是数字,字母或者下划线 ( ...
- Android开发之网络请求HttpURLConnection
转:http://blog.csdn.net/guolin_blog/article/details/12452307 Android中主要提供了两种方式来进行HTTP操作,HttpURLConnec ...
- [leetcode72]Edit Distance(dp)
题目链接:https://leetcode.com/problems/edit-distance/ 题意:求字符串的最短编辑距离,就是有三个操作,插入一个字符.删除一个字符.修改一个字符,最终让两个字 ...
- mysqldump批量导出(多张表)表结构及表数据
Mysql 批量导出表结构(数据) 仅导出结构,不导出数据: 1.导出數據库為dbname的表结构 mysqldump -h主机地址 -u用户名 -p密码 -d dbname >db.s ...
- 如何使用 Java 测试 IBM Systems Director 的 REST API
转自: http://www.ibm.com/developerworks/cn/aix/library/au-aix-systemsdirector/section2.html 如何使用 Java ...
- jenkins mac slave 设置
1.在jenkins上增加节点, 2,在mac系统中将ssh的服务打开在偏好设置- 互联网与无线 - 共享中 3,使用mac root用户修改sshd-config的鉴权方式 首先获取到root用户登 ...
- Android公共库(缓存 下拉ListView 下载管理Pro 静默安装 root运行 Java公共类)
介绍总结的一些android公共库,包含缓存(图片缓存.预取缓存).公共View(下拉及底部加载更多ListView.底部加载更多ScrollView.滑动一页Gallery).及Android常用工 ...
- poj 3101 Astronomy (java 分数的最小公倍数 gcd)
题目链接 要用大数,看了别人的博客,用java写的. 题意:求n个运动周期不完全相同的天体在一条直线上的周期. 分析:两个星球周期为a,b.则相差半周的长度为a*b/(2*abs(a-b)),对于n个 ...