我下载AspNetPager不知道对DataList如何进行分页。我想知道后台代码是什么。        DataTable dt = GetTop.GetAllProduct(s);
        PagedDataSource pds = new PagedDataSource();
        this.AspNetPager1.RecordCount = dt.Rows.Count;
        pds.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
        pds.DataSource = dt.DefaultView;
        this.DataList1.DataSource = pds;
        this.DataList1.DataBind();
        if (this.DataList1.Items.Count < 0)
        {
            this.div1.Visible = true;
            Label18.Text = "暂无数据";
            this.div11.Visible = false;
        }
        else {
            this.div1.Visible = false;
            this.div11.Visible = true;
        }应该如何修改

解决方案 »

  1.   

    大概就是这样了,自己看吧            int rowcount = 0;
                rp_datalist.DataSource = cc.GetCompanyList(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, " T_4012 DESC,T_4001 DESC ", _cond, out rowcount);
                rp_datalist.DataBind();
                GridView gv = new GridView();
                AspNetPager1.RecordCount = rowcount;
            /// <summary>
            /// 获取记录数
            /// </summary>
            /// <param name="table"></param>
            /// <param name="cond">格式:Where ...</param>
            /// <returns></returns>
            public int GetRowCount(string table, string cond)
            {
                int rowcount = 0;
                string query = string.Format("Select count(*) From {0} {1}", table, cond);
                using (IDataReader reader = DbHelper.ExecuteReader(CommandType.Text, query))
                {
                    if (reader.Read()) rowcount = reader.GetInt32(0);                return rowcount;
                }
            }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="table"></param>
            /// <param name="rowpage"></param>
            /// <param name="rowcount"></param>
            /// <param name="orderFid"></param>
            /// <param name="Conditions"></param>
            /// <returns></returns>
            public DataTable GetinfoList(string table, int rowpage, int rowcount, string orderFid, string Conditions)
            {            string query = "Select * From "
                    + "(Select *,ROW_NUMBER() OVER(ORDER BY {2}) as RowNum From {4} {3}) as newTable "
                    + "Where (RowNum BETWEEN ({0}) AND ({1}))";
                query = string.Format(query, (rowpage - 1) * rowcount + 1, rowpage * rowcount, orderFid, Conditions, table);            //string query = "Select top {0} * From {1} {2} and id not in(Select top {3} id From {1} {2} Order by {4}) Order by {4}";
                //query = string.Format(query, rowcount, table, Conditions, (rowpage - 1) * rowcount + 1, orderFid);
                return DbHelper.ExecuteTable(CommandType.Text, query);        }
      

  2.   

    DEMO
      

  3.   

    用aspnetpager实现datalist分页(绝对的简单实用) 
      

  4.   

    参考我的百度里的GridView1例子,测试通过
      

  5.   

    干嘛不存储过程分页???protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    UserCheck.CheckLoginUserVoid("../");
                    CardsView();
                }
               
            }
            protected void CardsView()
            {
                if (Session["company_id"] != null)
                {
                    int cid = Convert.ToInt32(Session["company_id"]);
                    var cardList = cardManage.GetAllCardsByProc(cid, anpCardList.PageSize, anpCardList.CurrentPageIndex,1);
                    anpCardList.RecordCount = cardList.Count;
                    this.rptCards.DataSource = cardList;
                    this.rptCards.DataBind();
                }
            }
    //---数据范访问层
    /// <summary>
            /// 存储过程分页,全部数据
            /// </summary>
            /// <param name="c_cid">当前用户ID</param>
            /// <param name="pageSize">每页显示行数</param>
            /// <param name="pageIndex">页码,第n页</param>
            /// <param name="c_sid">状态ID,[1表示正常],[2表示已删除]</param>
            /// <returns></returns>
            public static IList<MuCard> GetAllCardsByProc(int c_cid, int pageSize, int pageIndex,int c_sid)
            {
                
                string procText = ConfigurationManager.AppSettings["Pages"].ToString();
                IList<MuCard> cardList = new List<MuCard>();
                MuCard card = null;
                SqlParameter[] pars = new SqlParameter[] 
                {
                    new SqlParameter("@pageSize",pageSize),
                    new SqlParameter("@pageIndex",pageIndex),
                    new SqlParameter("@c_cid",c_cid),
                    new SqlParameter("@c_sid",c_sid)
                };
                using (SqlDataReader dr = SqlHelper.ExecProcdureReturnDataReader(procText,CommandType.StoredProcedure,pars))
                {
                    while (dr.Read())
                    {
                        card = new MuCard();
                        card.CID = Convert.ToInt32(dr[0]);
                        card.C_Name = dr[1].ToString();
                        card.C_ComName = dr[2].ToString();
                        card.C_Tel = dr[3].ToString();
                        card.C_Mobile = dr[4].ToString();
                        card.C_GID =Convert.ToInt32( dr[5]);
                        cardList.Add(card);
                    }
                }
                return cardList;
            }
      

  6.   

    补充:上面还是我/// <summary>
            /// 分页
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void anpCardList_PageChanged(object sender, EventArgs e)
            {            CardsView();
            }
         <webdiyer:AspNetPager ID="anpCardList"
            PageSize="15" runat="server" Visible="true"
            ShowPageIndex="true"
            FirstPageText="首页"
            LastPageText="尾页"
            AlwaysShow="True"
            NextPageText="下一页" 
            PrevPageText="前一页"
            ShowPageIndexBox="Always"
            ShowNavigationToolTip="True"
            onpagechanged="anpCardList_PageChanged" 
            MoreButtonClass=""
            
            NumericButtonCount="5"
            NumericButtonType="Image"
            
            PageIndexBoxType="DropDownList">
        </webdiyer:AspNetPager>
      

  7.   

    控件针对的是数据库而不是什么控件即使是reteapter也是一样的
      

  8.   

    如何?你这话应该如何理解?我是说用AspNetPager插件对DataList进行分页?难道说错了?
      

  9.   

    传个list 就ok!private void TestPage(IList<testInfo> list)
        {
            PagedDataSource pd = new PagedDataSource();
            pd.AllowPaging = true;
            pd.PageSize = this.AspNetPager1.PageSize;
            pd.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;        this.AspNetPager1.RecordCount = list.Count;        pd.DataSource = list;
            this.DataList1.DataSource = pd;
            this.DataList1.DataBind();
        }