/// <summary>
/// 分頁鏈接
/// </summary>
/// <param name=pageSize></param>
/// <param name=recordCount></param>
/// <param name=currentPage></param>
/// <param name=prev>當前頁前面顯示的數量</param>
/// <param name=next>當前頁後面顯示的數量</param>
/// <returns></returns>
public string PageLink(int pageSize int recordCount int currentPage int prev int next)
{
int pageCount = recordCount % pageSize == ? (recordCount / pageSize) : ((int)MathCeiling((double)recordCount / pageSize));
StringBuilder sb = new StringBuilder();
if (currentPage > && recordCount > )
{
sbAppend(<a href=\?page=);
sbAppend((currentPage )ToString());
sbAppend(\>前一頁</a> );
}
if (currentPage > prev + )
sbAppend(<a href=\?page=\></a> );
if (currentPage < prev)
next = next + prev currentPage + ;
if (next > pageCount currentPage)
prev = prev + next (pageCount currentPage);
for (int i = ; i <= pageCount; i++)
{
if (i == currentPage)
{
sbAppend(<a href=\?page= + i + \ class=\current\ ><font color=\red\> + i + </font></a> );
}
else
{
if (i > (currentPage prev ) && i < (currentPage + next + ))
{
sbAppend(<a href=\?page= + i + \> + i + </a> );
}
}
}
if (currentPage < pageCount next)
sbAppend( <a href=\?page= + pageCountToString() + \> + pageCountToString() + </a>);
if (currentPage < pageCount)
sbAppend( <a href=\?page= + (currentPage + )ToString() + \>後一頁</a>);
return sbToString();
}
From:http://tw.wingwit.com/Article/program/net/201311/13867.html