下面利用分页控件实现分页功能。分页控件下载网址:http://www.webdiyer.com/ 从该网址下载AspNetPager.dll后,在VS2008中在工具箱中,右键 —> 选择项 —> 浏览 找到AspNetPager.dll添加至工具箱中,在工具箱中可以找到下图所示


数据绑定用Reapter控件
●把两个控件拖拽至Web窗体中(如:test.aspx)。
●AspNetPager控件的属性中可以设置每页显示记录数(如图)。


●存储过程中的代码代码如下

  1. set ANSI_NULLS ON
  2. set QUOTED_IDENTIFIER ON
  3. GO
  4. -- =============================================
  5. -- Author:      myroom
  6. -- Create date: 2009-12-6
  7. -- Description: 新闻表的分页
  8. -- =============================================
  9. ALTER PROCEDURE [dbo].[prceNewsPagerSelectAll]
  10. @startIndex int,
  11. @endIndex int
  12. AS
  13. BEGIN
  14. with temptbl as(
  15. select ROW_NUMBER() OVER (ORDER BY id desc)AS Row,* from news
  16. )
  17. SELECT Row,title FROM temptbl where Row between @startIndex and @endIndex
  18. END
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: myroom
-- Create date: 2009-12-6
-- Description: 新闻表的分页
-- =============================================
ALTER PROCEDURE [dbo].[prceNewsPagerSelectAll]
@startIndex int,
@endIndex int
AS
BEGIN
with temptbl as(
select ROW_NUMBER() OVER (ORDER BY id desc)AS Row,* from news
)
SELECT Row,title FROM temptbl where Row between @startIndex and @endIndex
END

●执行该存储过程

  1. exec prceNewsPagerSelectAll 1,5
exec prceNewsPagerSelectAll 1,5

(从news 表中先出第1至第5条记录)查看结果。
●数据访问层中

  1. //选出新闻表中总记录个数
  2. public int NewsRecordCount()
  3. {
  4. string cmdText="select * from news";
  5. int rc = (sqlhelper.ExecuteQuery(cmdText, CommandType.Text)).Rows .Count ;
  6. return rc;
  7. }
  8. //新闻表分页功能
  9. public DataTable SelectNewsPager(int startIndex, int endIndex)
  10. {
  11. DataTable dt = new DataTable();
  12. string cmdText = "prceNewsPagerSelectAll";
  13. SqlParameter[] paras = new SqlParameter[] {
  14. new SqlParameter ("@startIndex",startIndex ),
  15. new SqlParameter ("@endIndex",endIndex )
  16. };
  17. dt = sqlhelper.ExecuteQuery(cmdText, paras, CommandType.StoredProcedure);
  18. return dt;
  19. }
 //选出新闻表中总记录个数
public int NewsRecordCount()
{
string cmdText="select * from news";
int rc = (sqlhelper.ExecuteQuery(cmdText, CommandType.Text)).Rows .Count ;
return rc;
}
//新闻表分页功能
public DataTable SelectNewsPager(int startIndex, int endIndex)
{
DataTable dt = new DataTable();
string cmdText = "prceNewsPagerSelectAll";
SqlParameter[] paras = new SqlParameter[] {
new SqlParameter ("@startIndex",startIndex ),
new SqlParameter ("@endIndex",endIndex )
};
dt = sqlhelper.ExecuteQuery(cmdText, paras, CommandType.StoredProcedure);
return dt;
}

●后台代码中(test.aspx.cs)

  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. if (!Page .IsPostBack )
  4. {
  5. int totalRecord = new NewsDAO().NewsRecordCount();//获取总记录数
  6. AspNetPager1.RecordCount = totalRecord;//对AspNetPager属性进行设置
  7. databind();
  8. }
  9. }
  10. //AspNetPager1控件的PageChanged事件
  11. protected void AspNetPager1_PageChanged(object sender, EventArgs e)
  12. {
  13. databind();
  14. }
  15. //数据绑定方法
  16. private void databind()
  17. {
  18. int startIndex = AspNetPager1.StartRecordIndex;//StartRecordIndex是AspNetPager固有属性
  19. int endIndex = AspNetPager1.EndRecordIndex;//EndRecordIndex是AspNetPager固有属性
  20. //数据绑定
  21. Repeater1.DataSource = new NewsDAO().SelectNewsPager(startIndex, endIndex);
  22. Repeater1.DataBind();
  23. }
 protected void Page_Load(object sender, EventArgs e)
{
if (!Page .IsPostBack )
{
int totalRecord = new NewsDAO().NewsRecordCount();//获取总记录数
AspNetPager1.RecordCount = totalRecord;//对AspNetPager属性进行设置
databind();
}
}
//AspNetPager1控件的PageChanged事件
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
databind();
}
//数据绑定方法
private void databind()
{
int startIndex = AspNetPager1.StartRecordIndex;//StartRecordIndex是AspNetPager固有属性
int endIndex = AspNetPager1.EndRecordIndex;//EndRecordIndex是AspNetPager固有属性
//数据绑定
Repeater1.DataSource = new NewsDAO().SelectNewsPager(startIndex, endIndex);
Repeater1.DataBind();
}

●效果图如下:

●对该控件的属性进行设置还有更多效果:

.NET基于分页控件实现真分页功能的更多相关文章

  1. 如何Windows分页控件中增加统计功能

    在我的博客里面,很多Winform程序里面都用到了分页处理,这样可以不管是在直接访问数据库的场景还是使用网络方式访问WCF服务获取数据,都能获得较好的效率,因此WInform程序里面的分页控件的使用是 ...

  2. .NetCore 实现分页控件(URL分页)实战

    上一篇文章介绍了分页控件的具体实现方式,接下来我们就来做一个分页控件 后台数据处理就过度的介绍,下面针对URL分页中的下面几点做说明: 1.搜索条件的状态保持 2.点击分页需要带上搜索条件 3.页码的 ...

  3. 基于MVC框架layui分页控件实现前端分页信息写法

    详细链接:https://shop499704308.taobao.com/?spm=a1z38n.10677092.card.11.594c1debsAGeak@{ ViewBag.Title = ...

  4. 自定义分页控件-基于Zhifeiya的分页控件改版

    基于Zhifeiya的分页控件改版的分页. html显示代码: <div class="pagelist"> {{.pagerHtml}} </div> c ...

  5. AspNetPager分页控件

    AspNetPager分页控件解决了分页中的很多问题,直接采用该控件进行分页处理,会将繁琐的分页工作变得简单化,下面是我如何使用AspNetPager控件进行分页处理的详细代码:1.首先到www.we ...

  6. 【转】AspNetPager分页控件用法

    AspNetPager分页控件解决了分页中的很多问题,直接采用该控件进行分页处理,会将繁琐的分页工作变得简单化,下面是我如何使用AspNetPager控件进行分页处理的详细代码: 1.首先到www.w ...

  7. asp.net分页控件库

    AspNetPager分页控件 AspNetPager分页控件解决了分页中的很多问题,直接采用该控件进行分页处理,会将繁琐的分页工作变得简单化,下面是我如何使用AspNetPager控件进行分页处理的 ...

  8. 自己动手用Javascript写一个无刷新分页控件

    .NET技术交流群:337901356 ,欢迎您的加入! 对 于一个用户体验好的网站来说,无刷新技术是很重要的,无刷新,顾名思义,就是局部刷新数据,有用过Asp.net Web Form技术开发网页的 ...

  9. WPF 分页控件 WPF 多线程 BackgroundWorker

    WPF 分页控件 WPF 多线程 BackgroundWorker 大家好,好久没有发表一篇像样的博客了,最近的开发实在头疼,很多东西无从下口,需求没完没了,更要命的是公司的开发从来不走正规流程啊, ...

随机推荐

  1. SaltStack 批量执行脚本

    这里演示如何使用 salt-master 对多台 salt-minion 批量执行脚本,步骤如下: [root@localhost ~]$ cat /srv/salt/top.sls # 先定义入口配 ...

  2. C语言的f(open)函数(文件操作/读写)

    头文件:#include <stdio.h> fopen()是一个常用的函数,用来以指定的方式打开文件,其原型为:     FILE * fopen(const char * path, ...

  3. 微信小程序--消息推送配置Token令牌错误校验失败如何解决

    微信开放第三方API接口, 申请地址: https://mp.weixin.qq.com/advanced/advanced?action=interface&t=advanced/inter ...

  4. 【gitlab】创建ssh 秘钥

    1).首先打开linux服务器,输入命令:ls -al ~/.ssh,检查是否显示有id_rsa.pub或者id_dsa.pub存在,如果存在请直接跳至第3步. 2).在bash中输入,注意这个地方的 ...

  5. JAVA知多少

    读<java解惑>感觉有意思的就记录一下. 1.判断奇数还是偶数 public boolean isOdd(int i){ return i%2==1; }; 这样子看起来很对,但是考虑到 ...

  6. java框架---->quartz的使用(一)

    Quartz 是个开源的作业调度框架,为在 Java 应用程序中进行作业调度提供了简单却强大的机制.今天我们就来学习一下它的使用,这里会分篇章对它进行介绍.只是希望能有个人,在我说没事的时候,知道我不 ...

  7. Android studio 插件安装

    安装插件步骤 一 CodeGlance 最大的用途:可用于快速定位代码.显示在右侧 二 Android Studio Prettify 可以将代码中的字符串写在string.xml文件中 选中字符串鼠 ...

  8. What you should know about .so files

    In its early days, the Android OS was pretty much supporting only one CPU architecture: ARMv5.Do you ...

  9. LeetCode 13 Roman to Integer(罗马数字转为整数)

    题目链接 https://leetcode.com/problems/roman-to-integer/?tab=Description   int toNumber(char ch) { switc ...

  10. JUnit(>4.0)@BeforeClass、@Before、@Test、@After、@AfterClass、@Ignore

    JUnit 4 开始使用 Java 5 中的注解(annotation),常用的几个 annotation 介绍: @BeforeClass:针对所有测试,只执行一次,且必须为static void ...