간단 하고 사용 하기 좋 은 ASP.NET 페이지 클래스(AJAX 지원,사용자 정의 텍스트 지원)
사용법:
var ps=new PageString();
/* */
ps.SetIsEnglish = true;// ( :false)
ps.SetIsShowText = true;// ( :true)
//ps.TextFormat="" ( :《span class=\"pagetext\"》《strong》 《/strong》:{0} 《strong》 《/strong》:{1}/{2}《/span》)
//ps.SetPageIndexName Request["pageIndex"]( :"pageIndex")
ps.SetIsAjax = false;// ( :"false")
/* */
int total = 10000;
int pageSize = 10;
int pageIndex = Convert.ToInt32(Request["pageIndex"]);
var page = ps.ToString(total, pageSize, pageIndex, "/UI/PageStringTest.aspx?");
// page html
Response.Write(page);
효과:코드:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace SyntacticSugar
{
/// <summary>
/// ** :
/// ** :2015-5-29
/// ** :-
/// ** :sunkaixuan
public class PageString
{
/// <summary>
/// ( :false)
/// </summary>
public bool SetIsEnglish { get; set; }
/// <summary>
/// ( :true)
/// </summary>
public bool SetIsShowText { get; set; }
/// <summary>
/// ( :"pagination")
/// </summary>
public string SetClassName { get; set; }
/// <summary>
/// ( :"pageIndex")
/// </summary>
public string SetPageIndexName { get; set; }
/// <summary>
/// href='' onclick=ajaxPage() ( :false)
/// </summary>
public bool SetIsAjax { get; set; }
/// <summary>
///
/// string.Format("{0}{1}{2}"," "," "," ")
/// :《span class=\"pagetext\"》《strong》 《/strong》:{0} 《strong》 《/strong》:{1}/{2}《/span》
/// </summary>
public string SetTextFormat { get; set; }
public PageString()
{
SetIsEnglish = false;
SetIsShowText = true;
SetTextFormat = "<span class=\"pagetext\"><strong> </strong>:{0} <strong> </strong>:{1}/{2}</span> ";
SetClassName = "pagination";
SetPageIndexName = "pageIndex";
SetIsAjax = false;
}
/*
.pagination .click {cursor:pointer}
.pagination a{text-decoration: none;border: 1px solid #AAE;color: #15B;font-size: 13px;border-radius: 2px;}
.pagination span{ color:#666;font-size:13px;display: inline-block;border: 1px solid #ccc;padding: 0.2em 0.6em;}
.pagination span.pagetext{ border:none}
.pagination a:hover{background: #26B;color: #fff;}
.pagination a{display: inline-block;padding: 0.2em 0.6em;}
.pagination .page_current{background: #26B;color: #fff;border: 1px solid #AAE;margin-right: 5px;}
.pagination{margin-top: 20px;}
.pagination .current.prev, .pagination .current.next{color: #999;border-color: #999;background: #fff;}
* */
/// <summary>
/// < > 20 1 2 3 4 5 6 7 8 9 10
/// </summary>
/// <param name="total"> </param>
/// <param name="pageSize"> </param>
/// <param name="pageIndex"> </param>
/// <param name="query_string">Url </param>
/// <returns></returns>
public string ToString(int total, int pageSize, int pageIndex, string query_string)
{
int allpage = 0;
int next = 0;
int pre = 0;
int startcount = 0;
int endcount = 0;
StringBuilder pagestr = new StringBuilder();
pageIndex = pageIndex == 0 ? 1 : pageIndex;
pagestr.AppendFormat("<div class=\"{0}\" >", SetClassName);
if (pageIndex < 1) { pageIndex = 1; }
//
if (pageSize != 0)
{
allpage = (total / pageSize);
allpage = ((total % pageSize) != 0 ? allpage + 1 : allpage);
allpage = (allpage == 0 ? 1 : allpage);
}
next = pageIndex + 1;
pre = pageIndex - 1;
startcount = (pageIndex + 5) > allpage ? allpage - 9 : pageIndex - 4;//
//
endcount = pageIndex < 5 ? 10 : pageIndex + 5;
if (startcount < 1) { startcount = 1; } // , 1 1
if (allpage < endcount) { endcount = allpage; }// +5 ,
bool isFirst = pageIndex == 1;
bool isLast = pageIndex == allpage;
if (SetIsShowText)
pagestr.AppendFormat(SetTextFormat, total, pageIndex, allpage);
if (isFirst)
{
pagestr.Append("<span> </span> <span> </span>");
}
else
{
pagestr.AppendFormat("<a href=\"{0}pageIndex=1\"> </a> <a href=\"{0}pageIndex={1}\"> </a>", query_string, pre);
}
// , ,
for (int i = startcount; i <= endcount; i++)
{
bool isCurent = pageIndex == i;
if (isCurent)
{
pagestr.Append(" <a class=\"page_current\">" + i + "</a>");
}
else
{
pagestr.Append(" <a href=\"" + query_string + "pageIndex=" + i + "\">" + i + "</a>");
}
}
if (isLast)
{
pagestr.Append("<span> </span> <span> </span>");
}
else
{
pagestr.Append(" <a href=\"" + query_string + "pageIndex=" + next + "\"> </a> <a href=\"" + query_string + "pageIndex=" + allpage + "\"> </a>");
}
pagestr.AppendFormat("</div>");
return ConversionData(pagestr.ToString());
}
private string ConversionData(string page)
{
if (SetIsEnglish)
{
page= page.Replace(" ", "Previous").Replace(" ", "Next").Replace(" ", "total").Replace(" ", "Current").Replace(" ", "records").Replace(" ", "First").Replace(" ", "Last");
}
if (SetIsAjax)
{
var matches = Regex.Matches(page, @"href\="".*?""",RegexOptions.Singleline);
if (matches != null && matches.Count > 0)
{
foreach (Match m in matches)
{
page = page.Replace(m.Value, string.Format("class=\"click\" onclick=\"ajaxPage('{0}')\"", Regex.Match(m.Value, string.Format(@"{0}\=(\d+)", SetPageIndexName)).Groups[1].Value));
}
}
}
return page;
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
부트스트랩 ASP.NET에서 설정하는 법1) _Layout.cshtml 內 link로 bootstrap 참조 2) Nuget 패키지에서 BootStrap 다운로드 3) 하단 부트스트랩 예제 사이트 참고해서 프로젝트 개발 참고 :...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.