
#region 分页
/// <summary>
/// 分页
/// </summary>
/// <param name="page">当前页</param>
/// <param name="count">总数</param>
/// <param name="comurl">组合连接段</param>
/// <param name="prev">页数省略前置个数</param>
/// <param name="next">页数省略后置个数</param>
/// <returns>分页html字符串</returns>
public static string orderPage(int page, int count, string comurl, int prev, int next)
{
StringBuilder strPageHtml = new StringBuilder();
bool preflag = true;
bool nextflag = true;
for (int i = ; i <= count; i++)
{
//上一页
if (i == && page == )
{
strPageHtml.Append("<span class=\"disabled\"> < </span>");
}
else if(i== && page>)
{
strPageHtml.Append("<a href=\"?page=" + (page - ) + comurl + "\"> < </a>");
} //是否为当前页
if (count > ) //大于15则显示省略号
{
if (page == i)
{
strPageHtml.Append("<span class=\"current\">" + i + "</span>\n");
}
else
{
if (i > page) //一、处理当前页后面的页数
{
if (i - page > ) //保留当前页下有两页可选
{
if (count - i < next) //省略号后可选页
{
strPageHtml.Append("<a href=\"?page=" + i + comurl + "\">" + i + "</a>\n");
}
else
{
if (preflag == true)
{
strPageHtml.Append(" … ");
preflag = false;
}
}
}
else
{
strPageHtml.Append("<a href=\"?page=" + i + comurl + "\">" + i + "</a>\n");
}
}
else if (i < page) //二、处理当前页前面的页数
{
if (i > prev) //当前页前页数大于前置参数的页数
{
if (page - i > ) //保留当前页上有两页可选
{
if (nextflag==true)
{
strPageHtml.Append(" … ");
nextflag = false;
}
}
else
{
strPageHtml.Append("<a href=\"?page=" + i + comurl + "\">" + i + "</a>\n");
}
}
else
{
strPageHtml.Append("<a href=\"?page=" + i + comurl + "\">" + i + "</a>\n");
}
}
}
}
else
{
if (page == i)
{
strPageHtml.Append("<span class=\"current\">" + i + "</span>\n");
}
else
{
strPageHtml.Append("<a href=\"?page=" + i + comurl + "\">" + i + "</a>\n");
}
} //下一页
if (i == count && page == count)
{
strPageHtml.Append("<span class=\"disabled\"> > </span>");
}
else if (i == count && page < count)
{
strPageHtml.Append("<a href=\"?page=" + (page + ) + comurl + "\"> > </a>");
}
}
return strPageHtml.ToString();
}
#endregion
/**分页**/
.tr_page{ background:white;}
div.yellow{padding:7px;margin:3px;text-align:center;}
div.yellow a{border:#ccc 1px solid;padding:2px 5px;margin:2px;color:#;text-decoration:none;}
div.yellow a:hover{border:#f0f0f0 1px solid;color:#;}
div.yellow a:active{border:#f0f0f0 1px solid;color:#;}
div.yellow span.current{border:#d9d300 1px solid;padding:2px 5px;font-weight:bold;margin:2px;color:#fff;background-color:#d9d300;}
div.yellow span.disabled{border:#eee 1px solid;padding:2px 5px;margin:2px;color:#ddd;}
样式
<p>
<div class="yellow" runat="server" id="yellowpage"> </div>
</p>
标签
yellowpage.InnerHtml=orderPage(page,forNum,"",,);
调用