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 ...
随机推荐
- Spring中的mappingResources和mappingDirectoryLocations
今天使用Spring+Hibernate进行事务管理,按照顺序也就是配置,DataSource,Sessionfactory,事务管理器以及拦截器. DateSource可以直接使用Hibernate ...
- 【Latex】如何在Latex中插入伪代码 —— clrscode3e
1. 简介clrscode3e是<算法导论(第三版)>使用的伪代码的宏包,clrs其实表示的是Cormen.Leiserson.Rivest和Stein.它有个更老的版本clrscode, ...
- jenkins mac slave 设置
1.在jenkins上增加节点, 2,在mac系统中将ssh的服务打开在偏好设置- 互联网与无线 - 共享中 3,使用mac root用户修改sshd-config的鉴权方式 首先获取到root用户登 ...
- PL/SQL database character set(AL32UTF8) and Client character set(ZHS16GBK) are different 2012-04-11 13:01
启动PL/SQL Developer 报字符编码不一致错误 Database character set (AL32UTF8) and Client character set (ZHS16GBK) ...
- bzoj2792
首先想到二分答案是吧,设为lim 这道题难在判定,我们先不管将一个数变为0的条件 先使序列满足相邻差<=lim,这个正着扫一遍反着扫一遍即可 然后我们就要处理将一个数变为0的修改代价 当i变为0 ...
- HTTPS通信机制
概述 使用HTTP协议进行通信时,由于传输的是明文所以很容易遭到窃听,就算是加密过的信息也容易在传输中遭受到篡改,因此需要在HTTP协议基础上添加加密处理,认证处理等,有了这些处理机制的HTTP成为H ...
- HDU 1686 (KMP模式串出现的次数) Oulipo
题意: 求模式串W在母串T中出现的次数,各个匹配串中允许有重叠的部分. 分析: 一开始想不清楚当一次匹配完成时该怎么办,我还SB地让i回溯到某个位置上去. 后来仔细想想,完全不用,直接让模式串向前滑动 ...
- CSS强制英文换行
1. word-break:break-all;只对英文起作用,以字母作为换行依据 2. word-wrap:break-word; 只对英文起作用,以单词作为换行依据 3. white-space: ...
- uva 10054 The Necklac(欧拉回路)
明显的欧拉回路,把颜色作为点,建图后,做一遍欧拉回路.不过我是现学的,打印路径上纠结了一下,发现随着FindEuler()的递归调用的结束,不断把点压入栈中,从后向前打印,遇到"支路&quo ...
- macro names must be identifiers
1.错把 #include 写成了 #define 会报这个错 2.定义一个不存在的宏业会报这个错,如加了-DANDRO 而ANDRO不存在