pageindex.(要下班了,所以就不正了,回家有事.嘿嘿....)
//总共多少也,每页多少条,第几页
public string GetPageStr(int total, int per, int page)
{
int allpage = 0;
int next = 0;
int pre = 0;
int startcount = 0;
int endcount = 0;
if (page <1) { page = 1; }
if (per != 0)
{
allpage = (total / per);
allpage = ((total % per) != 0 ? allpage + 1 : allpage);
allpage = (allpage == 0 ? 1 : allpage);
}
next = page + 1;
pre = page - 1;
if (startcount <1)
{
startcount = 1;
}
if (allpage
{
endcount = allpage;
}
if (page > allpage)
{
page = allpage;
}
if (allpage>1)
{
pagestr = " ";
pagestr += page > 1 ? " " : "上一页 ";
pagestr += " ";
if (allpage > 10)
{
startcount = (page + 4) > allpage ? allpage - 10 : page - 4;
if (page <10)
{
for (int i = 1; i <=10; i++)
{
pagestr += page == i ? "" + i + "" : "" + i + "";
}
//pagestr += "... " + Convert.ToString(allpage - 1) + "";
pagestr += "..." + allpage + "";
}
else
if (page <= allpage - 8)
{
pagestr += " 1...";
//pagestr += " 2...";
for (int i = startcount; i <= startcount + 8; i++)
{
pagestr += page == i ? " " + i + "" : " " + i + "";
}
//pagestr += "... " + Convert.ToString(allpage - 1) + "";
pagestr += "..." + allpage + "";
}
else
{
pagestr += " 1...";
//pagestr += " 2...";
for (int i = allpage - 8; i <= allpage; i++)
{
pagestr += page == i ? " " + i + "" : " " + i + "";
}
}
}
else
{
for (int i = 1; i <= allpage; i++)
{
pagestr += page == i ? " " + i + "" : " " + i + "";
}
}
pagestr += " ";
pagestr += page != allpage ? " " : " 下一页";
}
return pagestr;
}
|