public static string GetPageBarStr(int pageIndex, int pageSize, int pageCount, int recordCount)
{
StringBuilder sb = new StringBuilder();
string domStrStart = "";
string domStrEnd = "";
if (pageIndex<1)
{
pageIndex = 1;
}
int start = pageIndex - 2;
if (start <= 2)
{
start = 2;
}
int end = start + 4;
if (end > pageCount)
{
end = pageCount;
start = end - 4;
if (start <= 2)
{
start = 2;
}
}
if (pageCount == 1)
{
start = 1;
}
// 1 ... 3 4 5 6 7 ... 12
if (start > 2)
{
domStrStart = "<span>...</span>";
}
if (pageCount - 1 > end)
{
domStrEnd = "<span>...</span>";
}
for (int i = start; i <= end; i++)
{
if (pageIndex != i)
{
sb.Append("<a href=‘javascript:void(0)‘ onclick=‘pageBarGo(" + (i) + ")‘>" + i + "</a>");
}
else
{
sb.Append("<span>" + i + "</span>");
}
}
StringBuilder sb2 = new StringBuilder();
if (pageIndex == 1)
{
sb2.Append("<div class=‘pageBarDiv‘><span>上一页</span>");
}
else
{
sb2.Append("<div class=‘pageBarDiv‘><a href=‘javascript:void(0)‘ onclick=‘pageBarGo(" + (pageIndex - 1) + ")‘>上一页</a>");
}
if (start != 1)
{
if (pageIndex != 1)
{
sb2.Append("<a href=‘javascript:void(0)‘ onclick=‘pageBarGo(1)‘>" + 1 + "</a>" + domStrStart);
}
else
{
sb2.Append("<span>" + 1 + "</span>" + domStrStart);
}
}
sb2.Append(sb.ToString());
if (end != pageCount)
{
if (pageIndex != pageCount && pageCount!=0)
{
sb2.Append(domStrEnd + "<a href=‘javascript:void(0)‘ onclick=‘pageBarGo(" + (pageCount) + ")‘>" + pageCount + "</a>");
}
else
{
sb.Append(domStrEnd + "<span>" + pageCount + "</span>");
}
}
if (pageIndex == pageCount || pageCount == 0)
{
sb2.Append("<span>下一页</span>");
}
else
{
sb2.Append("<a href=‘javascript:void(0)‘ onclick=‘pageBarGo(" + (pageIndex + 1) + ")‘>下一页</a>");
}
sb2.Append("共<span class=‘redspan‘>" + recordCount + "</span>条数据,每页显示<input type=‘text‘ value=‘" + pageSize + "‘ id=‘pageBar_pageSize‘/>条 转到<input type=‘text‘ value=‘" + pageIndex + "‘ id=‘pageBar_skip‘/><input type=‘button‘ value=‘确定‘ onclick=‘pageBarSkip()‘/></div><style>.pageBarDiv a {color:#915833; margin-right:5px;} .pageBarDiv span{ margin-right:5px;color:#444444;} .pageBarDiv input[type=‘text‘]{width:30px;color:#444444;} .pageBarDiv .redspan{margin-right:3px; margin-left:3px;color:red;} .pageBarDiv button{text-align:center;padding-left:3px;padding-right:3px;color:white;border:none;border-radius:2px;}</style>");
return sb2.ToString();
}