我想知道 怎么分页
是用PageDataSource 吗 如果是谁有详细的代码啊 新手啊 帮帮忙啊
还有DataList 是不是也和Repeater一样分页
是用PageDataSource 吗 如果是谁有详细的代码啊 新手啊 帮帮忙啊
还有DataList 是不是也和Repeater一样分页
解决方案 »
- C# .Net中在服务端將值賦給客户端变量
- 跳转后不执行 if(!Ispostback)中的事件了.......
- 返回的接口里的数据怎么获取?
- asp.net中cookie的使用
- 求blog源码供学习
- 我第一次安装pet shop 4.0,一运行就出现了错误请教!
- 如何保护asp.net的代码
- 同样是aspx为扩展名的文件,为什么其打开方式有的连接到IE,有的连接到记事本呢?
- 关于SqlDataReader数据操作的方法?
- 关于C#中使用SQL 的小问题(在线等待),急!!!!!!!!!!!-------------
- 在 ASP.NET 中如何嵌入 HTML,实现类似 <jsp:include /> 的功能?
- GridView绑定数据源问题
取数据源 Ds
PagedDataSource pds = new PagedDataSource();
pds.DataSource = Ds.Table["表名"].DefaultView;
pds.AllowPaging = true;//允许分页
pds.PageSize = 12;//每页显示的记录数
pds.CurrentPageIndex = 0;//当前页索引
Repeater1.DataSource = pds;
Repeater1.DataBind();
这些是基本的一些代码 还要加上些处理 你自己再查查资料 有点烦琐
可以在摆渡搜索一下,也可以在我网站上找到www.dffd.net
(
@DepartmentID int,
@PageNumber int, --页号
@ProductsPerPage int, --平均一页要显示的个数
)
as
--创建一个临时表@Products,此表可帮助实现分页
declare @Products table
(
Row int not null identity(1,1),
ProductID int,
ProductName varchar(50),
)--将表Product中的信息完整的插入到临时表@Products中
insert into @Products
select ProductID,
ProductName,
from
(
select distinct p.ProductID,
ProductName,
from Product as p inner join CategoryProduct as cp
on p.ProductID = cp.ProductID inner join Category as c
on cp.CategoryID = c.CategoryID inner join DepartmentCategory as dc
on c.CategoryID = dc.CategoryID inner join Department as d
on dc.DepartmentID = d.DepartmentID
where p.onDepartmentPromotion = 1
and d.DepartmentID = @DepartmentID
) as ProductOnDepPr
--返回经输入参数限定的查询记录集
select ProductID,
ProductName,
from @Products
where Row > (@PageNumber - 1) * @ProductsPerPage
and Row <= @PageNumber * @ProductsPerPage
go程序中把平均一页要显示多少个产品的数量和页码号一起做参数传给此存储过程,可以查到当前页码要显示的东西,希望对LZ有帮助
<%@Import namespace="System.Data.SqlClient"%>
<html>
<head>
<title>default</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="C#" runat="server">
public void Page_Load(Object src,EventArgs e)
{SqlConnection cnn=new SqlConnection("server=zzl;uid=sa;pwd=970480;database=zzl");//连接数据库
SqlDataAdapter mycommand=new SqlDataAdapter("select * from start1",cnn);//数据操作,而表start1及其数据自己sqlserver中做
DataSet ds=new DataSet();
mycommand.Fill(ds); //实例dataset对象为ds,并把数据填充到ds上
PagedDataSource pp=new PagedDataSource();//对分页功能的类实例对象
pp.DataSource=ds.Tables[0].DefaultView;//把数据赋予对象pp
pp.AllowPaging=true;//允许进行分页
pp.PageSize=6;//设置每页数据的个数
int cpage;//这个整数用来分析分页页数的
if(Request.QueryString["page"]!=null)//这个判断语句的作用是对cpage进行赋值
cpage=Convert.ToInt32(Request.QueryString["page"]);
else
cpage=1;
pp.CurrentPageIndex=cpage-1;//pp对象的当前引索值,因为引索值是从0开始,cpage从1开始所以要减1
if (!pp.IsFirstPage)//Request.CurrentExecutionFilePath为当前的程序的文件名,直接写也可以
pre.NavigateUrl=Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(cpage-1); if (!pp.IsLastPage)
next.NavigateUrl=Request.CurrentExecutionFilePath+ "?page=" + Convert.ToString(cpage+1);
repeater1.DataSource=pp;
repeater1.DataBind();}
</script>
</head>
<body>
<table width="100%" border="0">
<tr><TD> <asp:label id="current" runat="server"/></TD></tr>
<tr><td> <asp:hyperlink id="pre" runat="server"><<</asp:hyperlink>
<asp:hyperlink id="next" runat="server">>></asp:hyperlink></td></tr></table>
<asp:repeater id="repeater1" runat="server">
<itemtemplate>
<table width="100%" border="0">
<tr><td> <%#DataBinder.Eval(Container.DataItem,"product")%></td></tr>
<tr><td> </td></tr></table></itemtemplate></asp:repeater>
</body>
</html>
SELECT TOP 10 *
FROM TestTable
WHERE (ID NOT IN
(SELECT TOP 20 id
FROM TestTable
ORDER BY id))
ORDER BY ID
SELECT TOP 页大小 *
FROM TestTable
WHERE (ID NOT IN
(SELECT TOP 页大小*页数 id
FROM 表
ORDER BY id))
ORDER BY ID(利用Not In和SELECT TOP分页)效率次之,需要拼接SQL语句。
@sqlstr nvarchar(4000), --查询字符串
@currentpage int, --第N页
@pagesize int --每页行数
as
set nocount on
declare @P1 int, --P1是游标的id
@rowcount int
exec sp_cursoropen @P1 output,@sqlstr,
@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
select ceiling(1.0*@rowcount/@pagesize)
as 总页数--,@rowcount as 总行数,@currentpage as 当前页
set @currentpage=(@currentpage-1)*@pagesize+1
exec sp_cursorfetch @P1,16,@currentpage,@pagesize
exec sp_cursorclose @P1
set nocount off
(利用SQL的游标存储过程分页)效率最差,但是最为通用。