ASP.MET 实现 上一页1 2 3 4 5 下一页 下5页
3个回答
展开全部
写一个分页函数,赋好值就可以用了
public string ThePage(int i_RecordCount, int i_pagesize, int i_pageIndex, string i_PID, string i_CssClass)
{
int i_Pcount = 0;
int i_StartPageNum;
int i_EndPageNum;
string i_pagerString = "";
i_pagerString = i_pagerString + "<style type=\"text/css\">\n.CssPage {font-family: Arial, Helvetica, sans-serif;font-size: 12px;line-height: 25px;color: #333;text-decoration: none;}\na.CssPage:hover{font-family: Arial, Helvetica, sans-serif;font-size: 12px;line-height: 25px;color: #ff0000;text-decoration: underline;}\n</style>\n";
if (i_pagesize != 0)
{
i_Pcount = (i_RecordCount / i_pagesize);
i_Pcount = ((i_RecordCount % i_pagesize) != 0 ? i_Pcount + 1 : i_Pcount);
i_Pcount = (i_Pcount == 0 ? 1 : i_Pcount);
}
if (i_pageIndex <= 0) i_pageIndex = 1;
if (i_pageIndex > i_Pcount) i_pageIndex = i_Pcount;
i_StartPageNum = 1;
while (i_StartPageNum + 10 <= i_pageIndex)
{
i_StartPageNum = i_StartPageNum + 10;
}
i_EndPageNum = i_StartPageNum + 9;
if (i_EndPageNum > i_Pcount) i_EndPageNum = i_Pcount;
i_pagerString = i_pagerString + "<div class='" + i_CssClass + "' style='padding-left:20px;padding-right:20px'>共<b>" + i_Pcount + "</b>页 共有<b>" + i_RecordCount + "</b>记录 第<b>" + i_pageIndex + "</b>页 跳到第 [ ";
if (i_StartPageNum > 1)
{
i_pagerString = i_pagerString + "<a class='" + i_CssClass + "' href='?" + i_PID + "page=" + (i_StartPageNum - 1).ToString() + "' title='前十页'><font face='webdings'>7</font></a>";
}
for (int i_i = i_StartPageNum; i_i <= i_EndPageNum; i_i++)
{
if (i_i != i_pageIndex)
{
i_pagerString = i_pagerString + "<a class='" + i_CssClass + "' href='?" + i_PID + "page=" + i_i.ToString() + "'>" + i_i.ToString() + "</a> ";
}
else
{
i_pagerString = i_pagerString + "<b><font color=red>" + i_i.ToString() + "</font></b> ";
}
}
if (i_EndPageNum < i_Pcount) i_pagerString = i_pagerString + "<a class='" + i_CssClass + "' href='?" + i_PID + "page=" + (i_EndPageNum + 1).ToString() + "' title='下十页'><font face='webdings'>8</font></a>";
i_pagerString = i_pagerString + "] 页";
if (i_pageIndex != 1) i_pagerString = i_pagerString + "<a class='" + i_CssClass + "' href='?" + i_PID + "page=1'> 首页</a> <a class='" + i_CssClass + "' href='?" + i_PID + "page=" + (i_pageIndex - 1).ToString() + "'>上一页</a>";
if (i_Pcount != i_pageIndex) i_pagerString = i_pagerString + "<a class='" + i_CssClass + "' href='?" + i_PID + "page=" + (i_pageIndex + 1).ToString() + "'> 下一页</a> <a class='" + i_CssClass + "' href='?" + i_PID + "page=" + i_Pcount + "'>尾页</a>";
i_pagerString = i_pagerString + "</div>";
return i_pagerString;
}
public string ThePage(int i_RecordCount, int i_pagesize, int i_pageIndex, string i_PID, string i_CssClass)
{
int i_Pcount = 0;
int i_StartPageNum;
int i_EndPageNum;
string i_pagerString = "";
i_pagerString = i_pagerString + "<style type=\"text/css\">\n.CssPage {font-family: Arial, Helvetica, sans-serif;font-size: 12px;line-height: 25px;color: #333;text-decoration: none;}\na.CssPage:hover{font-family: Arial, Helvetica, sans-serif;font-size: 12px;line-height: 25px;color: #ff0000;text-decoration: underline;}\n</style>\n";
if (i_pagesize != 0)
{
i_Pcount = (i_RecordCount / i_pagesize);
i_Pcount = ((i_RecordCount % i_pagesize) != 0 ? i_Pcount + 1 : i_Pcount);
i_Pcount = (i_Pcount == 0 ? 1 : i_Pcount);
}
if (i_pageIndex <= 0) i_pageIndex = 1;
if (i_pageIndex > i_Pcount) i_pageIndex = i_Pcount;
i_StartPageNum = 1;
while (i_StartPageNum + 10 <= i_pageIndex)
{
i_StartPageNum = i_StartPageNum + 10;
}
i_EndPageNum = i_StartPageNum + 9;
if (i_EndPageNum > i_Pcount) i_EndPageNum = i_Pcount;
i_pagerString = i_pagerString + "<div class='" + i_CssClass + "' style='padding-left:20px;padding-right:20px'>共<b>" + i_Pcount + "</b>页 共有<b>" + i_RecordCount + "</b>记录 第<b>" + i_pageIndex + "</b>页 跳到第 [ ";
if (i_StartPageNum > 1)
{
i_pagerString = i_pagerString + "<a class='" + i_CssClass + "' href='?" + i_PID + "page=" + (i_StartPageNum - 1).ToString() + "' title='前十页'><font face='webdings'>7</font></a>";
}
for (int i_i = i_StartPageNum; i_i <= i_EndPageNum; i_i++)
{
if (i_i != i_pageIndex)
{
i_pagerString = i_pagerString + "<a class='" + i_CssClass + "' href='?" + i_PID + "page=" + i_i.ToString() + "'>" + i_i.ToString() + "</a> ";
}
else
{
i_pagerString = i_pagerString + "<b><font color=red>" + i_i.ToString() + "</font></b> ";
}
}
if (i_EndPageNum < i_Pcount) i_pagerString = i_pagerString + "<a class='" + i_CssClass + "' href='?" + i_PID + "page=" + (i_EndPageNum + 1).ToString() + "' title='下十页'><font face='webdings'>8</font></a>";
i_pagerString = i_pagerString + "] 页";
if (i_pageIndex != 1) i_pagerString = i_pagerString + "<a class='" + i_CssClass + "' href='?" + i_PID + "page=1'> 首页</a> <a class='" + i_CssClass + "' href='?" + i_PID + "page=" + (i_pageIndex - 1).ToString() + "'>上一页</a>";
if (i_Pcount != i_pageIndex) i_pagerString = i_pagerString + "<a class='" + i_CssClass + "' href='?" + i_PID + "page=" + (i_pageIndex + 1).ToString() + "'> 下一页</a> <a class='" + i_CssClass + "' href='?" + i_PID + "page=" + i_Pcount + "'>尾页</a>";
i_pagerString = i_pagerString + "</div>";
return i_pagerString;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询