下面利用分页控件实现分页功能。分页控件下载网址: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. Android--Led_Demo_APK控制LED灯

    下面代码主要实现接口定义,实现从.so库文件接口函数在JAVA里面的声明:package com.friendlyarm.AndroidSDK; import android.util.Log; pu ...

  2. Hadoop集群三种作业调度算法介绍

    Hadoop集群中有三种作业调度算法,分别为FIFO,公平调度算法和计算能力调度算法 先来先服务(FIFO) Hadoop中默认的调度器FIFO,它先按照作业的优先级高低,再按照到达时间的先后选择被执 ...

  3. 使用API函数EnumWindows()枚举顶层窗口

      http://simpleease.blog.163.com/blog/static/1596085820052770290/ 要枚举Windows当前所有打开的顶层窗口,可使用Windows A ...

  4. ASP/SQL 注入天书

    引言 随着 B/S 模式应用开发的发展,使用这种模式编写应用程序的程序员也越来越多.但是由于这个行业的入门门槛不高,程序员的水平及经验也参差不齐,相当大一部分程序员在编写代码的时候,没有对用户输入数据 ...

  5. jsp连接数据库的乱码问题 servlet请求参数编码处理get post

    1.在所有需要读取数据的地方用下面的方式.同时jsp必须统一编码,如我都是UTF-8 String userName= new String(request.getParameter("us ...

  6. 原生js--insertAdjacentHTML

    insertAdjacentHTML是IE浏览器提供向DOM中插入html字符串的方法,字符串会自动生成在DOM树中. 其调用方式为elem.insertAdjacentHTML( position, ...

  7. 禁用ngen版本的.NET Framework dll加载

    在调试时会发现出于性能考虑.NET Framework dll加载的都是ngen版本,比如:System.dll,实际加载System.ni.dll. 如果希望加载非ngen版本,可以设置系统环境变量 ...

  8. 一个lucene源码分析的博客

    ITpub上的一个lucene源码分析的博客,写的比较全面:http://blog.itpub.net/28624388/cid-93356-list-1/

  9. STM8L外部中断 为何 死循环 寄存器操作

    STM8L 系列单片机是 ST公司推出的低功耗单片机,与STM8S系列相比功耗降低了很多,但内部结构也删减了很多,使用时一定要仔细阅读手册.  这是第一次使用STM8,实现功能不是很复杂就没想研究库函 ...

  10. 【BZOJ1478】Sgu282 Isomorphism Pólya定理神题

    [BZOJ1478]Sgu282 Isomorphism 题意:用$m$种颜色去染一张$n$个点的完全图,如果一个图可以通过节点重新标号变成另外一个图,则称这两个图是相同的.问不同的染色方案数.答案对 ...