04
2012
07

C# 中的wenfrom 分页方法

分页有很多控件之类的~~~现在暂时发个临时版,可以用来扩展为控件之类的,懒的扩展了

#region 分页
int total = (int)Math.Ceiling(pageCount / (double)pageSize);
string url = "/sitemap-" + type.ToString().ToLower() + "-" + "{0}" + ".html ";
if (total == 1)
{
PageIndexHtml = string.Empty;
}
else
{
StringBuilder sb = new StringBuilder();
if (this.pageIndex > 1)
sb.AppendFormat("<a class=\"c_up_nocurrent\" href=\"{0}\">上一页</a>", string.Format(url, this.pageIndex - 1));
sb.Append("<div class=\"c_page_list layoutfix\">");

int jspageSize = 10;
int jsPageIndex = this.pageIndex - 5 < 0 || total <= jspageSize ? 0 : this.pageIndex - 5;
if (jsPageIndex + 10 > total && total - jspageSize > 0) jsPageIndex = total - jspageSize;

int jsPageEnd = jsPageIndex + 10;
if (jsPageEnd > total) jsPageEnd = total;
if (jsPageIndex > 0)
{
sb.AppendFormat("<a class=\"{0}\" href=\"{1}\">{2}</a>", "", string.Format(url, 1), 1);
sb.Append("<span class=\"c_page_ellipsis\">...</span>");
}
for (int i = jsPageIndex; i < jsPageEnd; i++)
{
sb.AppendFormat("<a class=\"{0}\" href=\"{1}\">{2}</a>", this.pageIndex == i + 1 ? "current" : "", string.Format(url, i + 1), i + 1);
}
if (jsPageEnd != total)
{
sb.Append("<span class=\"c_page_ellipsis\">...</span>");
sb.AppendFormat("<a class=\"{0}\" href=\"{1}\">{2}</a>", "", string.Format(url, total), total);
}
sb.Append("</div>");
if (this.pageIndex < total)
sb.AppendFormat("<a class=\"c_down\" href=\"{0}\">下一页</a>", string.Format(url, this.pageIndex + 1));
sb.Append("<div class=\"c_pagevalue\">到<input id=\"pageNum\" type=\"text\" class=\"c_page_num\" name=\"\" />页");
string js = @"var pageTolal= " + total + @"; var pageNum=_.$('pageNum');
if (/^\d+$/.test(pageNum.value)){
if(parseInt(pageNum.value) > pageTolal){
$alert(pageNum, $s2t('超出页码范围!'));}
}else{
$alert(pageNum, $s2t('请输入正确的页码!'));
}
window.location.href = '/sitemap-" + type.ToString().ToLower() + @"-'+pageNum.value+'.html';
";
sb.AppendFormat("<input type=\"button\" class=\"c_page_submit\" onclick=\"{0}\" value=\"确定\" name=\"\" /></div>", js);
PageIndexHtml = sb.ToString();
}
#endregion

来源:博客园

« 上一篇下一篇 »

评论列表:

1.地源热泵  2012/7/9 9:09:26 回复该留言
行为那张脸

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。