本文實(shí)例講述了asp.net實(shí)現(xiàn)簡(jiǎn)單分頁的方法。分享給大家供大家參考。
具體實(shí)現(xiàn)方法如下:
復(fù)制代碼 代碼如下:
/// summary>
/// 分頁內(nèi)容
/// /summary>
/// param name="size">頁面大小/param>
/// param name="count">頁面數(shù)量/param>
/// param name="currendIndex">當(dāng)前頁/param>
/// param name="pattern">url模式:demo.aspx?page={0}/param>
/// param name="target">窗口模式/param>
/// returns>/returns>
public static string get_pagenation(int size,
int count,
int currendIndex,
string pattern,
string target)
{
//1>打開窗口目標(biāo)
target = string.IsNullOrEmpty(target) ? "_top" : target;
//2>總頁數(shù)
int pageCount = count / size;
pageCount = pageCount * size == count ? pageCount : pageCount + 1;
//3>分頁內(nèi)容
StringBuilder strHtml = new StringBuilder();
strHtml.Append("span class='pagenation'>");
#region 首部處理
if (currendIndex > 1)
{
strHtml.AppendFormat("a href='1' target='{0}'>[首頁]/a>", target);
strHtml.AppendFormat("a href='{0}' target='{1}'>[上一頁]/a>", string.Format(pattern, currendIndex - 1), target);
}
else
{
strHtml.Append("span class='disabled'>[首頁]/span>nbsp;nbsp;span class='disabled'>[上一頁]/span>");
}
#endregion
#region 中間部分
int i = 1;
int right = (currendIndex + 4) > pageCount ? pageCount : currendIndex + 4;
if (currendIndex > 6)
{
i = currendIndex - 5;
}
else
{
right = pageCount >= 10 ? 10 : pageCount;
}
for (; i = right; i++)
{
if (i == currendIndex)
{
strHtml.AppendFormat("font class='current'>{0}/font>", i);
strHtml.AppendLine();
continue;
}
strHtml.AppendFormat("a href='{0}' target='{1}'>[{2}]/a>", string.Format(pattern, i), target, i);
strHtml.AppendLine();
}
#endregion
#region 尾部處理
if (currendIndex == pageCount)
{
strHtml.Append("span class='disabled'>[下一頁]/span>span class='disabled'>[末頁]/span>");
strHtml.AppendFormat("總共({0})頁", pageCount);
}
else
{
strHtml.AppendFormat("a href='{0}' target='{1}'>[下一頁]/a>", string.Format(pattern, currendIndex + 1), target);
strHtml.AppendFormat("a href='{0}' target='{1}'>[末頁]/a>", string.Format(pattern, pageCount), target);
strHtml.AppendFormat("nbsp;nbsp;label>總共({0})頁/label>", pageCount);
}
#endregion
strHtml.Append("/span>");
return strHtml.ToString();
}
希望本文所述對(duì)大家的asp.net程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:- asp.net利用后臺(tái)實(shí)現(xiàn)直接生成html分頁的方法
- ASP.NET無刷新分頁簡(jiǎn)單實(shí)現(xiàn)
- Asp.Net之JS生成分頁條的方法