<%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %> <webdiyer:AspNetPager id="AspNetPager1" runat="server" ShowPageIndexBox="Always" PageSize="20" OnPageChanged="AspNetPager1_PageChanged" TextBeforeInputBox="轉到第 " TextAfterInputBox=" 頁 " ShowPageIndex="False" ShowInputBox="Always" ShowCustomInfoSection="Left" PrevPageText="上一頁" NextPageText="下一頁" LastPageText="尾頁" FirstPageText="首頁" AlwaysShow="True" CustomInfoSectionWidth="600" CustomInfoTextAlign="NotSet" LayoutType="Table"> </webdiyer:AspNetPager> <webdiyer:AspNetPager ID="AspNetPager2" runat="server" CloneFrom="AspNetPager1"> </webdiyer:AspNetPager>
public void checkCase() { string strSql = " ID>0"; int num = bll.GetRecordCount(strSql); AspNetPager1.RecordCount = num; DataSet ds = bll.GetAspNetPagerDataSet(strSql, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize); if (ds.Tables[0].Rows.Count > 0) { this.Repeater1.DataSource = ds.Tables[0].DefaultView; this.Repeater1.DataBind(); AspNetPager1.CustomInfoHTML = "共:<font color=\"red\"><b>" + AspNetPager1.RecordCount.ToString() + "</b></font> 條記錄"; AspNetPager1.CustomInfoHTML += " 總頁數:<font color=\"red\"><b>" + AspNetPager1.PageCount.ToString() + "</b></font> 頁"; AspNetPager1.CustomInfoHTML += " 每頁顯示:<font color=\"red\"><b>" + AspNetPager1.PageSize.ToString() + "</b></font> 條"; AspNetPager1.CustomInfoHTML += " 當前頁:<font color=\"red\"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font> "; } }
bll html
/// <summary> /// 得到aspnetpager分頁數據 /// </summary> public DataSet GetAspNetPagerDataSet(string whereSql, int mypageindex, int mypagesize) { return dal.GetAspNetPagerList(whereSql, mypageindex, mypagesize); }
DALweb
/// <summary> /// 得到AspNetPager分頁數據列表 /// </summary> public DataSet GetAspNetPagerList(string strWhere, int mypageindex, int mypagesize) { StringBuilder strSql = new StringBuilder(); strSql.Append(" SELECT ID,sTitle,sContent,sAuthor,sAuthorTel,sAuthorQQ,sAuthorEmail,toDepart,ifPass,PubDate "); strSql.Append(" FROM QuestionBook "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } strSql.Append(" order by ID desc"); return SQLHelper.ExecuteWebDiyerDataset(SQLHelper.DBCONNECTIONSTRING, CommandType.Text, strSql.ToString(), mypageindex, mypagesize); }
DBTtilityui
#region 爲webdiyer分頁控件作的 DataSet 傳遞參數進來 DataSet ExecuteWebDiyerDataset(string connString, CommandType cmdType, string cmdText,int mypageindex,int mypagesize, params SqlParameter[] cmdParms) public static DataSet ExecuteWebDiyerDataset(string connString, CommandType cmdType, string cmdText, int mypageindex, int mypagesize, params SqlParameter[] cmdParms) { SqlDataAdapter myAdapter = new SqlDataAdapter(); myAdapter.SelectCommand = new SqlCommand(); using (SqlConnection conn = new SqlConnection(connString)) { PrepareCommand(myAdapter.SelectCommand, conn, null, cmdType, cmdText, cmdParms); DataSet ds = new DataSet(); myAdapter.Fill(ds, mypagesize * (mypageindex - 1), mypagesize, "dtable"); myAdapter.SelectCommand.Parameters.Clear(); return ds; } } #endregion