下面利用分页控件实现分页功能。分页控件下载网址: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
●执行该存储过程
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;
}
●后台代码中(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();
}
●效果图如下:
●对该控件的属性进行设置还有更多效果:
- 大小: 2.1 KB
- 大小: 7 KB
- 大小: 11.9 KB
- 大小: 3.8 KB
分享到:
相关推荐
.net 超强分页控件.net 超强分页控件.net 超强分页控件.net 超强分页控件.net 超强分页控件.net 超强分页控件.net 超强分页控件.net 超强分页控件
模仿淘宝的asp.net2.0 分页控件, 内符dll和说明.
自己写的一个很漂亮且强大的分页控件,简洁漂亮,非常不错!供大家分享
AspNetPager针对ASP.NET分页控件的不足,提出了与众不同的解决asp.net中分页问题的方案,即将分页导航功能与数据显示功能完全独立开来,由用户自己控制数据的获取及显示方式,因此可以被灵活地应用于任何需要实现...
.net mvc分页控件,自定义控件创建方法
基于asp.net2.0分页控件源码 配合分页存储过程,轻轻松松进行千万级数据分页。 关于该控件的技术文章和使用方法: 之一: http://blog.csdn.net/46539492/archive/2008/04/02/2244627.aspx 之二: ...
asp.net通用分页控件AspNetPager7.2
本资源在VS2015环境下通过自定义窗体库组合VB.NET已有控件实现DataGridView控件分页显示功能。
自己写的分页控件,在 http://download.csdn.net/source/3485783这个资源的基础上编译成DLL文件。同时支持MVC2 MVC3并有简单sample.非常简单。我相信大部分人能看懂我的sample 使用: 1、引用我的DLL 2、自己要坐...
.Net 分页控件各种样式大全,web前端分页控件大全
asp.net分页控件asp.net分页控件
C# Asp.Net数字分页控件,自定义控件的实际应用。 详细说明:http://www.our-code.com/news/2010719/n958250.html 有效果图和解释。 有新版本了:http://download.csdn.net/source/2560452
c#语言asp.net 不用分页控件对Gridview进行分页。vs2005工具编写的例子。
ASP.NET免费分页控件(dll文件,带说明),个人认为很好用的:)所以共享给大家
ASP.NET MVC Linq to SQL 实现数据库增删改(源代码)ASP.NET MVC Linq to SQL 实现数据库增删改(源代码) ASP.NET MVC 分页控件
asp.net分页控件的使用方法
此文件为一个ASP.NET AJAX的服务器分页控件,提供了分页控件的程序集,以及少量的实例代码,其中还有不少BUG,希望贴出来跟大家一起研究一下,修改里面的不足之处。该控件的开发是出于本人额外兴趣。
三种风格的分页控件以及分页控件的 dll
ASP.NET分页控件(最新版)很好用的可以自定义分页样式!