祝賀一下~好不容易把分頁做出來了
現在用aspNetPager控件做出的真分頁
首先在SqlHelper
Code
/**//// <summary>
/// 獲取分頁數據
/// </summary>
/// <param name=
/// <param name=
/// <param name=
/// <param name=
/// <returns></returns>
public static DataSet GetPage(string sql
{
openCon();
sqlDs
sqlDa = new SqlDataAdapter(sql
int startRow = (currentPage
sqlDa
recordcount = GetPageRecord(sql);
closeCon();
return sqlDs;
}
//返回總的記錄數
public static int GetPageRecord(string sql)
{
openCon();
sql = Regex
sql =
sqlCmd = new SqlCommand(sql
int recordcount = int
closeCon();
return recordcount;
}
然後在BLL層新建一個PageManager
Code
/**//// <summary>
/// 獲取分頁數據
/// </summary>
/// <param name=
/// <param name=
/// <param name=
/// <param name=
/// <returns></returns>
public static DataSet GetPage(string sql
{
return SQLHelper
}
需分頁的數據綁定處是這樣的
Code
<asp:Repeater ID=
<ItemTemplate>
<tr>
<td align=
<td align=
</tr>
</ItemTemplate>
</asp:Repeater>
然後在綁定代碼下方加上分頁控件(當然這個可以隨便放
Code
<!
<div >
<webdiyer:AspNetPager ID=
FirstPageText=
onpagechanged=
PRevPageText=
TextBeforePageIndexBox=
CustomInfoHTML=
</webdiyer:AspNetPager>
</div>
最後在aspx
Code
/**//// <summary>
/// 綁定帶有分頁的新聞列表
/// </summary>
public void BindRepeater()
{
int caid = int
string Sql =
int CurrentPage = AspNetPager
int PageSize = AspNetPager
int RecordCount;
DataSet ds = PageManager
AspNetPager
AspNetPager
repNewsList
repNewsList
}
別忘了
protected void Page_Load(object sender
{
if (!Page
{
BindRepeater();
}
}
還有分頁控件的PageChanged事件裡也調用一下
protected void AspNetPager
{
BindRepeater();
}
最後再補充一個非常漂亮的翻頁樣式
Code
<style>
{}{
font
}
{}{
background:#
border:
color:#FFFFFF;
font
margin:
padding:
}
{}{
background:#FFFFFF none repeat scroll
border:
color:#
margin:
padding:
text
}
{}{
background:#
border:
color:#FFFFFF;
}
</style>
然後在AspNetPager中加上以下四個屬性
CSSClass=
CurrentPageButtonClass=
CustomInfoClass=
CustomInfoTextAlign=
From:http://tw.wingwit.com/Article/program/ASP/201311/21651.html