datalist 分页

前台:
   <webdiyer:AspNetPager SubmitButtonClass="buttons"  ID="AspNetPager1" runat="server" AlwaysShow="True" FirstPageText="首页"
                        NextPageText="下一页" PrevPageText="前一页" LastPageText="尾页" PageSize="15" ShowInputBox="Always"
                        OnPageChanged="AspNetPager1_PageChanged">
                    </webdiyer:AspNetPager>   
   <!-- PageSize="15"定义每页显示数据条数 -->
后台:
        /// <summary>
        /// 加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)

        {
         BoundList();
         }
       /// <summary>
        /// 全局的变量,分页用的参数数据信息总数
        /// </summary>
        public static int sumcount;
        /// <summary>
        /// 绑定信息数据
        /// </summary>
        private void BoundList()
        {
            DataTable dt = GetList().Tables[0];//获取数据源
            
            if (dt.Rows.Count > 0)
            {
                sumcount = dt.Rows.Count;
                PagedDataSource pds = new PagedDataSource();
                AspNetPager1.RecordCount = sumcount;
                pds.AllowPaging = true;
                pds.PageSize = AspNetPager1.PageSize;
                pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
                pds.DataSource = dt.DefaultView;
                this.gridView1.DataSource = pds; //可以绑定到Gridview 、datalist等数据控件上,此处为Gridview
                this.gridView1.DataBind();
            }
            else
            {
                AspNetPager1.RecordCount = 0;
                this.gridView1.DataSource = null;
                gridView1.EmptyDataText = "没有相关信息!";
                this.gridView1.DataBind();
            }
        }

        /// <summary>
        /// 分页控件的翻页事件
        /// </summary>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BoundList();
        }
原文地址:https://www.cnblogs.com/a1235202005/p/2680551.html