asp.net

位置:IT落伍者 >> asp.net >> 浏览文章

ASP.NET分页链接方法


发布日期:2022年10月25日
 
ASP.NET分页链接方法

/// <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>&nbsp;&nbsp;);

}

if (currentPage > prev + )

sbAppend(<a href=\?page=\></a>&nbsp;&nbsp;);

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>&nbsp;&nbsp;);

}

else

{

if (i > (currentPage prev ) && i < (currentPage + next + ))

{

sbAppend(<a href=\?page= + i + \> + i + </a>&nbsp;&nbsp;);

}

}

}

if (currentPage < pageCount next)

sbAppend(&nbsp;<a href=\?page= + pageCountToString() + \> + pageCountToString() + </a>);

if (currentPage < pageCount)

sbAppend(&nbsp;&nbsp;<a href=\?page= + (currentPage + )ToString() + \>后一页</a>);

return sbToString();

}

上一篇:ASP.NET MVC: DictionaryValueProvider

下一篇:利用ASP.NET访问共享网络资源