我想知道 怎么分页 
是用PageDataSource 吗 如果是谁有详细的代码啊 新手啊 帮帮忙啊
还有DataList 是不是也和Repeater一样分页

解决方案 »

  1.   

    可以用相同的方法分页  
    取数据源  Ds
    PagedDataSource pds = new PagedDataSource();
    pds.DataSource = Ds.Table["表名"].DefaultView;
    pds.AllowPaging = true;//允许分页
    pds.PageSize = 12;//每页显示的记录数
    pds.CurrentPageIndex = 0;//当前页索引
    Repeater1.DataSource = pds;
    Repeater1.DataBind();
    这些是基本的一些代码   还要加上些处理   你自己再查查资料   有点烦琐
      

  2.   

    用aspnetpager分页控件分。
    可以在摆渡搜索一下,也可以在我网站上找到www.dffd.net
      

  3.   

    create procedure GetProductsonDepartmentPromotion
    (
    @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有帮助
      

  4.   

    以前有人发过的:<%@Import namespace="System.Data"%>
    <%@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>&nbsp;&nbsp;<asp:label id="current" runat="server"/></TD></tr>
      <tr><td>&nbsp;<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>&nbsp;&nbsp;<%#DataBinder.Eval(Container.DataItem,"product")%></td></tr>
     <tr><td>&nbsp;&nbsp;</td></tr></table></itemtemplate></asp:repeater>
    </body>
    </html>
      

  5.   

    利用Not In和SELECT TOP分页
    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语句。
      

  6.   

    利用SQL的游标存储过程分页create  procedure XiaoZhengGe
    @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的游标存储过程分页)效率最差,但是最为通用。 
      

  7.   

    PageDataSource,或者存储过程分页,还有一中方法是用DataGridPageChangeEvents 这个是我常用的方法,自己写控件