protected void Page_Load(object sender, EventArgs e)
    {        if (!IsPostBack)
        {            ArticleList();
            //ClassList();
        }
    }    private void ArticleList()
    {//AspNetPager分页控件如何用
        Database db = new Database();
        DataSet ds = db.GetDataSet("Select * From Article");
        Repeater1.DataSource = ds;
        Repeater1.DataBind();
       
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e) 
    {
        ArticleList();
    } 在上述的DataSet中AspNetPager分页控件如何用。

解决方案 »

  1.   

    前台页面:
     <webdiyer:aspnetpager id="AspNetPager1" runat="server" horizontalalign="Center" onpagechanged="AspNetPager1_PageChanged"
            showcustominfosection="Left" width="400px" meta:resourceKey="AspNetPager1" style="font-size:14px" InputBoxStyle="width:19px"
            CustomInfoHTML="Page  <font color='red'><b>%CurrentPageIndex%</b></font> of  %PageCount%&nbsp;&nbsp;Order %StartRecordIndex%-%EndRecordIndex%" ShowNavigationToolTip="True" CustomInfoTextAlign="Center" ShowInputBox="Always" FirstPageText="【首页】" LastPageText="【尾页】" NextPageText="【下页】 " PageSize="3" PrevPageText="【前页】 " UrlPaging="true">
    </webdiyer:aspnetpager>后台代码:
    protected void Page_Load(object sender, EventArgs e)
        {        if (!IsPostBack)
            {            ArticleList();
                //ClassList();
            }
        }    private void ArticleList()
        {//AspNetPager分页控件如何用
            Database db = new Database();
           Database db = new Database();
           DataSet ds = db.GetDataSet("Select * From Article"); 
           DataView dv = ds.Tables[0].DefaultView;
           PagedDataSource pds = new PagedDataSource();
           AspNetPager1.RecordCount = dv.Count;
           pds.DataSource = dv;
           pds.AllowPaging = true;
           pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
           pds.PageSize = AspNetPager1.PageSize;
           Repeater1.DataSource = pds;
           Repeater1.DataBind();      
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            ArticleList();
        } 
      

  2.   

    上面代码是根据我用过的改了一下,我的原来代码如下所示:前台代码:
     <webdiyer:aspnetpager id="AspNetPager1" runat="server" horizontalalign="Center" onpagechanged="AspNetPager1_PageChanged"
            showcustominfosection="Left" width="400px" meta:resourceKey="AspNetPager1" style="font-size:14px" InputBoxStyle="width:19px"
            CustomInfoHTML="Page  <font color='red'><b>%CurrentPageIndex%</b></font> of  %PageCount%&nbsp;&nbsp;Order %StartRecordIndex%-%EndRecordIndex%" ShowNavigationToolTip="True" CustomInfoTextAlign="Center" ShowInputBox="Always" FirstPageText="【首页】" LastPageText="【尾页】" NextPageText="【下页】 " PageSize="3" PrevPageText="【前页】 " UrlPaging="true"></webdiyer:aspnetpager>
          
    后台代码:
     BaseClass bc = new BaseClass(); protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataListDataBind();
            }    
        }
    protected void DataListDataBind()
        {
            DataSet ds = bc.GetDataSet("select * from [reply] order by replyDate desc", "reply");
            DataView dv = ds.Tables[0].DefaultView;
            PagedDataSource pds = new PagedDataSource();
            AspNetPager1.RecordCount = dv.Count;
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
            pds.PageSize = AspNetPager1.PageSize;        this.DataList1.DataSource = pds;
            this.DataList1.DataBind();         }    protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {        
            DataListDataBind();
        }
      

  3.   

    这是吴旗娃的AspNetPager,呵呵,下面的使用日记保证你几分钟能入门呵呵。 http://blog.csdn.net/zhangxuyu1118/archive/2008/10/21/3116957.aspx
      

  4.   

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:DataList ID="DataList1" runat="server">
                <ItemTemplate>
                    Name:
                    <asp:Label ID="LName" runat="server" Text='<%# Eval("Name") %>'>
                    </asp:Label><br />
                    <br />
                </ItemTemplate>
            </asp:DataList>
            <webdiyer:aspnetpager id="pager1" runat="server" onpagechanged="ChangePage"></webdiyer:aspnetpager>    
        </div>
        </form>
    </body>
    </html>后置代码:default.aspx.cs using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using cpp114.tools.oledb;
    using System.Data.OleDb;
    using Wuqi.Webdiyer;public partial class test_Default : System.Web.UI.Page
    {
        protected OleDbConnection conn = new OleDbConnection();
        protected OleDbCommand cmd = new OleDbCommand();    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                initdb();
                conn.Open();
                cmd.CommandText = "select count(*) from user";
                pager1.RecordCount = (int)cmd.ExecuteScalar();
                conn.Close();
                BindData();
                           
            }    }
     
     //初始化连接对象
        protected void initdb(){
            conn.ConnectionString = oledbtool.myConnStr + Server.MapPath(oledbtool.mydbName);
            cmd.Connection = conn;        
        } //数据绑定
        protected void BindData() {
            initdb();
            OleDbDataAdapter sda = new OleDbDataAdapter("select * from user",conn);       
            DataSet ds = new DataSet();
            sda.Fill(ds, pager1.PageSize * (pager1.CurrentPageIndex - 1), pager1.PageSize, "temptbl");
            DataList1.DataSource = ds.Tables["temptbl"];
            DataList1.DataBind();
        } //翻页事件
        protected void ChangePage(object src, PageChangedEventArgs e)
        {
            pager1.CurrentPageIndex = e.NewPageIndex;
            BindData();
        }    }
      

  5.   

        #region AspNetPagerQuerySql
        /// <summary>
        /// AspNetPagerQuerySql
        /// </summary>
        /// <param name="PageIndex">Index Page</param>
        /// <param name="PageSize">Page Size</param>
        /// <param name="Sql">Sql String</param>
        /// <param name="srTable">TableName</param>
        /// <param name="error">errorInfomation</param>
        /// <returns>DataSet</returns>
        public override DataSet AspNetPagerQuerySql(int PageIndex, int PageSize, string Sql, string srTable, out string error)
        {
          //throw new Exception("The method or operation is not implemented.");
          error = null;
          DataSet ds = new DataSet();
          com.CommandText = Sql;
          sda = new SqlDataAdapter(com);
          try
          {
            sda.Fill(ds,PageIndex*PageSize,PageSize,srTable);
          }
          catch (Exception e)
          {
            error = e.Message;
          }
          return ds;
        }
        #endregion
      

  6.   


    楼主:
    你写的代码大体上没有错误。不过在ArticleList()函数中要控制一下分页。private void ArticleList()
    {
    int pageindex = 0;//第几页
                if (AspNetPager1.CurrentPageIndex < 1)
                {
                    pageindex = 0;
                }
                else
                {
                    pageindex = AspNetPager1.CurrentPageIndex - 1;
                }            int RowCount = 20;//每页显示的数量            //DataTable dt = PagingSearch("earch", "id", "", 20, pageindex, "", "", "id");
               //这里我用的是一个分页存储过程。      Repeater1.DataSource = dt; 
            Repeater1.DataBind(); }你这样试试!!!!!
    不要用,找我!!!! 呵呵。
      

  7.   


    楼主:
    你写的代码大体上没有错误。不过在ArticleList()函数中要控制一下分页。private void ArticleList()
    {
    int pageindex = 0;//第几页
                if (AspNetPager1.CurrentPageIndex < 1)
                {
                    pageindex = 0;
                }
                else
                {
                    pageindex = AspNetPager1.CurrentPageIndex - 1;
                }            int RowCount = 20;//每页显示的数量            //DataTable dt = PagingSearch("earch", "id", "", 20, pageindex, "", "", "id");
               //这里我用的是一个分页存储过程。      Repeater1.DataSource = dt; 
            Repeater1.DataBind(); }你这样试试!!!!!
    不要用,找我!!!! 呵呵。