.NET基于分页控件实现真分页功能
下面利用分页控件实现分页功能。分页控件下载网址:http://www.webdiyer.com/ 从该网址下载AspNetPager.dll后,在VS2008中在工具箱中,右键 —> 选择项 —> 浏览 找到AspNetPager.dll添加至工具箱中,在工具箱中可以找到下图所示
数据绑定用Reapter控件
●把两个控件拖拽至Web窗体中(如:test.aspx)。
●AspNetPager控件的属性中可以设置每页显示记录数(如图)。
●存储过程中的代码代码如下
- 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
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
●执行该存储过程
- exec prceNewsPagerSelectAll 1,5
exec prceNewsPagerSelectAll 1,5
(从news 表中先出第1至第5条记录)查看结果。
●数据访问层中
- //选出新闻表中总记录个数
- 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;
- }
//选出新闻表中总记录个数
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)
- 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();
- }
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基于分页控件实现真分页功能的更多相关文章
- 如何Windows分页控件中增加统计功能
在我的博客里面,很多Winform程序里面都用到了分页处理,这样可以不管是在直接访问数据库的场景还是使用网络方式访问WCF服务获取数据,都能获得较好的效率,因此WInform程序里面的分页控件的使用是 ...
- .NetCore 实现分页控件(URL分页)实战
上一篇文章介绍了分页控件的具体实现方式,接下来我们就来做一个分页控件 后台数据处理就过度的介绍,下面针对URL分页中的下面几点做说明: 1.搜索条件的状态保持 2.点击分页需要带上搜索条件 3.页码的 ...
- 基于MVC框架layui分页控件实现前端分页信息写法
详细链接:https://shop499704308.taobao.com/?spm=a1z38n.10677092.card.11.594c1debsAGeak@{ ViewBag.Title = ...
- 自定义分页控件-基于Zhifeiya的分页控件改版
基于Zhifeiya的分页控件改版的分页. html显示代码: <div class="pagelist"> {{.pagerHtml}} </div> c ...
- AspNetPager分页控件
AspNetPager分页控件解决了分页中的很多问题,直接采用该控件进行分页处理,会将繁琐的分页工作变得简单化,下面是我如何使用AspNetPager控件进行分页处理的详细代码:1.首先到www.we ...
- 【转】AspNetPager分页控件用法
AspNetPager分页控件解决了分页中的很多问题,直接采用该控件进行分页处理,会将繁琐的分页工作变得简单化,下面是我如何使用AspNetPager控件进行分页处理的详细代码: 1.首先到www.w ...
- asp.net分页控件库
AspNetPager分页控件 AspNetPager分页控件解决了分页中的很多问题,直接采用该控件进行分页处理,会将繁琐的分页工作变得简单化,下面是我如何使用AspNetPager控件进行分页处理的 ...
- 自己动手用Javascript写一个无刷新分页控件
.NET技术交流群:337901356 ,欢迎您的加入! 对 于一个用户体验好的网站来说,无刷新技术是很重要的,无刷新,顾名思义,就是局部刷新数据,有用过Asp.net Web Form技术开发网页的 ...
- WPF 分页控件 WPF 多线程 BackgroundWorker
WPF 分页控件 WPF 多线程 BackgroundWorker 大家好,好久没有发表一篇像样的博客了,最近的开发实在头疼,很多东西无从下口,需求没完没了,更要命的是公司的开发从来不走正规流程啊, ...
随机推荐
- Java中获取资源文件的方法总结
这里总结3中方法获取资源文件的 ServletContext Class ClassLoader 文件的位置 1. ServletContext public void doGet(HttpServl ...
- Zabbix的自定义键值和自动发现功能监控Oracle数据库的表空间
前面介绍了利用Orabbix监控了,参考zabbix通过Orabbix监控oracle数据库,这里我们原先的模板中进行了修改,使用自动发现功能实现监控tablespace的使用情况. 1. 在被监控的 ...
- DRBD架构详解(原创)
DRBD概述Distributed Replicated Block Device(DRBD)是一种基于软件的,无共享,复制的存储解决方案,在服务器之间的对块设备(硬盘,分区,逻辑卷等)进行镜像.DR ...
- List 集合的N层遍历
package com.j1.cms.model; import java.io.Serializable; import java.util.List; /** * Created by wangc ...
- fastcgi模式下设置php最大执行时间
php在执行中常见错误: The FastCGI process exceeded configured request timeout: FastCGI process exceeded confi ...
- UML类图的几种关系总结【转】
在UML类图中,常见的有以下几种关系: 泛化(Generalization), 实现(Realization),关联(Association),聚合(Aggregation),组合(Composit ...
- Swift - static和class的使用
Swift中表示 “类型范围作用域” 这一概念有两个不同的关键字,它们分别是static和class.这两个关键字确实都表达了这个意思,但是在其他一些语言,包括Objective-C中,我们并不会特别 ...
- C常见机试题
初级: 一.请编写函数long fun(long int x),功能是:将长整型数x中每一位上为奇数的数依次取出,并逆序和顺序分别构成一个新数返回. 例如:程序运行时输入123456789,输出: ...
- LeetCode 13 Roman to Integer(罗马数字转为整数)
题目链接 https://leetcode.com/problems/roman-to-integer/?tab=Description int toNumber(char ch) { switc ...
- 剑指offer题目记录
1.如下为类型CMyString的声明,请为该类型添加赋值运算符函数. class CMyString { public: CMyString(char* pData = NULL); CMyStri ...