全部數據列表使用aspnetpager分頁

一、引入AspNetPager

將aspnetpager.dll複製到web/bin 文件夾。


添加引用

<code>  /<code>

前臺頁碼引用代碼

二、DAL

<code>///        /// 顯示全部數據        ///        public DataTable GetListAll()       {            StringBuilder strSql = new StringBuilder();            strSql.Append("select * from title");                return new SqlHelper().ExecuteQuery(strSql.ToString(), CommandType.Text);       } ///        /// 分頁        ///        ///        ///        ///        public DataTable SelectbyPage(string startIndex, string endIndex) //當前頁的首條頁碼參數starIndex和最後頁碼參數endIndex       {            string sql = " with temptbl as ( SELECT ROW_NUMBER() OVER (ORDER BY id desc)AS Row, * from title) SELECT * FROM temptbl where Row between @startIndex and @endIndex";            SqlParameter[] sqlParameters = { new SqlParameter("@startIndex", startIndex),                                              new SqlParameter("@endIndex",endIndex)};            DataTable dt = new SqlHelper().ExecuteQuery(sql, sqlParameters, CommandType.Text);                      return dt;           }/<code>

三、後臺代碼

<code>using Wuqi.Webdiyer; protected void Page_Load(object sender, EventArgs e)   {         if (!IsPostBack)       {             int totalOrders = new DAL.title().GetListAll().Rows.Count;             AspNetPager1.RecordCount = totalOrders;             //bindData(); //使用url分頁,只需在分頁事件處理程序中綁定數據即可,無需在Page_Load中綁定,否則會導致數據被綁定兩次       }   }     private void bindData()   {         RepList1.DataSource =new DAL.title().SelectbyPage(AspNetPager1.StartRecordIndex.ToString(), AspNetPager1.EndRecordIndex.ToString());         RepList1.DataBind();   }     protected void AspNetPager1_PageChanged(object src, EventArgs e)   {         bindData();   }/<code>

主要是:統計總記錄條數、數據綁定

四、效果圖