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 ...
随机推荐
- c# 使用 静态类+xml序列化 保存配置文件
namespace TVCorrectionDataProcess{ [XmlRoot(ElementName = "Config")] public class Co ...
- 初学者的checklist:对于QTP,你应该知道的9个基本概念
学习QTP或者其他相关任何工具的方法都是首先把基本的概念过一遍.正所谓砍柴不怕磨刀功,一旦你对这些概念熟悉了,你就可以学习该工具的高级部分了.写这篇文章的目标是列出初学QTP的人应该掌握的所有基本概念 ...
- UVa 11524 - InCircle
推公式 #include <cstdio> #include <cmath> double Cal( double a, double b, double c ) { retu ...
- PHP无限极分类生成树方法
你还在用浪费时间又浪费内存的递归遍历无限极分类吗,看了该篇文章,我觉得你应该换换了.这是我在OSChina上看到的一段非常精简的PHP无限极分类生成树方法,整理分享了. function genera ...
- fil_system_struct
/** The tablespace memory cache */ typedef struct fil_system_struct fil_system_t; /** The tablespace ...
- UVa 11762 (期望 DP) Race to 1
设f(x)表示x转移到1需要的次数的期望,p(x)为不超过x的素数的个数,其中能整除x的有g(x)个 则有(1-g(x)/p(x))的概率下一步还是转移到x,剩下的情况各有1/p(x)的概率转移到x/ ...
- Jqgrid入门-别具特色的Pager Bar (四)
Pager Bar位于表格最下边.默认情况下,分为三部分.如图: 第一部分:导航按钮栏(Navigator) 第二部分:页码栏(Pager) 第三部分:记录信息栏(Record) 要实 ...
- web交互方式
轮询:客户端定时向服务器发送Ajax请求,服务器接到请求后马上返回响应信息并关闭连接. 优点:后端程序编写比较容易. 缺点:请求中有大半是无用,浪费带宽和服务器资源. 实例:适于小型应用. 长轮询:客 ...
- 为apache单独编译mod_rewrite.so
今天要把一个站点搬到一台Red Hat 4.1.2-42系统上,在配置rewrite的时候,发现apache没有mod_rewrite,可能是当初编译apache的时候没有带上 --enable-re ...
- LeetCode: Interval
(1)Merge Intervals https://leetcode.com/problems/merge-intervals/ Given a collection of intervals, m ...