哪位前辈能指点一下我啊。怎么分页?

caoailin 2004-08-30 12:42:01
DataSet中可以进行分页吗?如何实现啊?。。
或是从数据库中直接从第几条到第几条。这样不是很麻烦。 又要怎么实现呢? 请高手指教 ,感激涕零

using System;
using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace List
{

public class index:Page

{

public DataList myList;
private void Page_Load(Object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source="+Server.MapPath("Data.mdb"));
OleDbDataAdapter da = new OleDbDataAdapter("select * from news",conn);
DataSet ds = new DataSet();
da.Fill(ds,"news");
myList.DataSource=ds.Tables["news"].DefaultView;
myList.DataBind();
}

}
}

...全文
187 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
37350792 2004-11-08
  • 打赏
  • 举报
回复
其实最主要的是一个通用的存储过程,对其进行分页!
一般分页是根据主键的排序方式来的!我把我常用的分页过程写出来供你分享吧!:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


ALTER procedure up_Page
(
@pagesize int, --你定义一页的行数
@pageindex int, --你要查看的当前页
@key varchar(20) , --记录的关键码
@select varchar(2000) ,--查询记录的语句
@From varchar(800) , --from 语句
@where varchar(800) --条件语句



)
as
set nocount on



create table #indextable (id int identity(1,1),nid int)
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex-1)*@pagesize
set @PageUpperBound=@PageLowerBound+@pagesize
set rowcount @PageUpperBound


exec ('insert #indextable (nid) select '+@key+' ' +@from+ @where + ' order by ' +@key +' --desc')
declare @a varchar(8000)


set @where =' where 1 = 1 '

set @a= @Select+' '+@From +' O,#indextable t ' + @where + 'and O.' + @key +'=t.nid and t.id>'+cast(@PageLowerBound as varchar(10))+' and t.id<='+cast(@PageUpperBound as varchar(10))+' order by t.id'


exec(@a)


set nocount off



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

hanxi077 2004-10-29
  • 打赏
  • 举报
回复
存储过程分页!!
lmdxr 2004-10-27
  • 打赏
  • 举报
回复
可以在DataGrid里面设置的啊.
37350792 2004-10-27
  • 打赏
  • 举报
回复
DataSet 中是没有分页的功能,因为它只是一个内存块,存放一个或多个表的数据.
一般在数据较多的情况下,使用自定义分页,这样性能较快!!

数据较少时,可使用DataGrid上的分页功能.

自定义分页,一般是使用存存储过程,传入你的页码和页长,返回你需要的结果集!
amendajing 2004-10-27
  • 打赏
  • 举报
回复
可以用ds.Table[0].Rows.Count来循环判断
leiyu1112 2004-10-27
  • 打赏
  • 举报
回复
楼上的啊!datagrid里面的设置好象也不行哦,以前我都试过。。。。。。
happyjun2000 2004-10-23
  • 打赏
  • 举报
回复
顶,接点分^_^
无聊就接分来了
zhpsam109 2004-09-04
  • 打赏
  • 举报
回复
http://dotnet.aspx.cc
3ss 2004-09-03
  • 打赏
  • 举报
回复
up
wangdequan1024 2004-09-02
  • 打赏
  • 举报
回复
Up
wangdequan1024 2004-09-02
  • 打赏
  • 举报
回复
UPUP
Coder李海波 2004-09-02
  • 打赏
  • 举报
回复
数据库sql分页处理,效率高
http://www.cnblogs.com/Sniper
jkflyfox 2004-09-02
  • 打赏
  • 举报
回复
可以使用zjcxc(邹建) 分页存储。http://community.csdn.net/Expert/topic/2864/2864072.xml?temp=.5489618
vzxq 2004-09-01
  • 打赏
  • 举报
回复
用分页存储过程
Jenyli2004 2004-08-31
  • 打赏
  • 举报
回复
只取出所需记录
select top "+ PageSize +" id ,title FROM table1 where id not in (select top " + (intCurrentPage - 1)*PageSize + " id from table1)";

PageSize:页面大小

intCurrentPage:当前页

希望能有帮助
孟子E章 2004-08-30
  • 打赏
  • 举报
回复
http://dotnet.aspx.cc/ShowDetail.aspx?id=108B1516-53CE-4357-B061-17295AF9689F

17,748

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧