search
HomeWeb Front-endHTML Tutorial自动化分页,HTML代码控制 思想_html/css_WEB-ITnose

1、绑定分页数据

  Request:主要是获取当前查询中所参与的所有条件

  pageSize:分页显示数量

  totalCount:分页总数

  currentPageStr:自定义参数(后面会更新该参数的用法和途径)

  tab:自定义参数(后面会更新该参数的用法和途径,和上面currentPageStr配合使用,需优化)

  pageIndexNumber:页面上显示当前页前、后多少页数数的数字

      如:显示当前页前后个5页的数字

  IsShouCount:是否显示总数量

2、用法,Response.Write页面输出一段html

<div class="m-t-20 paging">            <pre class="brush:php;toolbar:false">            <%Response.Write(ZCJExtensions.Pager(Request, 40, iCount, "pi",IsShouCount:true));%>            

 

 

3、源代码 方法主要用到请求头类的使用,HttpRequest 

public static class ZCJExtensions{    /// <summary>    /// 分页Pager显示(分页请求字符串默认为pi)    /// </summary>    /// <param name="pageSize">每页记录的数量</param>    /// <param name="totalCount">总记录数</param>    /// <param name="pageIndexNumber">显示页索引的数量</param>    /// <returns></returns>    public static string Pager(int pageSize, int totalCount,int pageIndexNumber = 10)    {        return ZCJExtensions.Pager(HttpContext.Current.Request, pageSize, totalCount, "pi", "", pageIndexNumber);    }    /// <summary>    /// 分页Pager显示        /// </summary>    /// <param name="requ">请求</param>    /// <param name="pageSize">每页记录的数量</param>    /// <param name="totalCount">总记录数</param>    /// <param name="currentPageStr">请求字符串</param>    /// <param name="tab">切换ID</param>    /// <param name="pageIndexNumber">显示页索引的数量</param>    /// <returns></returns>    public static string Pager(HttpRequest requ, int pageSize, int totalCount, string currentPageStr = "1",string tab="",int pageIndexNumber = 10,bool IsShouCount=false)    {        //var queryString = html.ViewContext.HttpContext.Request.QueryString;        string html = "";        var queryString = requ.QueryString;        int currentPage = 1; //当前页            var totalPages = Math.Max((totalCount + pageSize - 1) / pageSize, 1); //总页数            //var dict = new System.Web.Routing.RouteValueDictionary(html.ViewContext.RouteData.Values);        var dict = new System.Web.Routing.RouteValueDictionary(requ.Form);        var output = new System.Text.StringBuilder();        var url = requ.Url.AbsolutePath + "?" + currentPageStr + "=(*)";        if (tab.Length > 0)        {            url += "&tab=" + tab;        }        //与相应的QueryString绑定           foreach (string key in queryString.Keys)        {            if (!string.IsNullOrEmpty(key) && queryString[key] != null )            {                dict[key] = queryString[key];                if (key != currentPageStr && key.ToLower()!="tab")                {                    url += "&" + key + "=" + queryString[key];                }            }        }        //获取 ~/Page/{page number} 的页号参数          int.TryParse((dict[currentPageStr] != null) ? dict[currentPageStr].ToString() : "0", out currentPage);        if (currentPage <= 0) currentPage = 1;        if (totalPages > 1)        {            if (currentPage != 1)            {                dict[currentPageStr] = 1;                //output.AppendFormat("{0} ", html.RouteLink("<<", dict));                var pageunm = "1";                var tempurl = url.Replace("(*)", pageunm);                output.AppendFormat("{0}", "<a href='" + tempurl + "'>首页</a>");            }            if (currentPage > 1)            {                //处理上一页的连接                    dict[currentPageStr] = currentPage - 1;                var pageunm = (currentPage - 1).ToString();                var tempurl = url.Replace("(*)", pageunm);                //output.Append(html.RouteLink("<", dict));                output.Append("<a href='" + tempurl + "'>上一页</a>");            }            else            {                //output.Append("<span><</span>");            }            output.Append("");            int currint = pageIndexNumber / 2;            for (int i = 0; i <= pageIndexNumber; i++)            {                //一共最多显示10个页码,前面5个,后面5个                    if ((currentPage + i - currint) >= 1 && (currentPage + i - currint) <= totalPages)                    if (currint == i)                    {                        //当前页处理                            output.Append(string.Format("<span>{0}</span>", currentPage));                    }                    else                    {                        //一般页处理                           dict[currentPageStr] = currentPage + i - currint;                        var pageunm = (currentPage + i - currint).ToString();                        var tempurl = url.Replace("(*)", pageunm);                        //output.Append(html.RouteLink((currentPage + i - currint).ToString(), dict));                        output.Append("<a href='" + tempurl + "'>" + pageunm + "</a>");                    }                output.Append("");            }            if (currentPage < totalPages)            {                //处理下一页的链接                   dict[currentPageStr] = currentPage + 1;                var pageunm = (currentPage + 1).ToString();                //output.Append(html.RouteLink(">", dict));                var tempurl = url.Replace("(*)", pageunm);                output.Append("<a href='" + tempurl + "'>下一页</a>");            }            else            {                //output.Append(">");            }            output.Append("");            if (currentPage != totalPages)            {                dict[currentPageStr] = totalPages;                var pageunm = totalPages.ToString();                var tempurl = url.Replace("(*)", pageunm);                //output.Append(html.RouteLink(">>", dict));                output.Append("<a href='" + tempurl + "'>尾页</a>");            }            output.Append(" ");        }        output.AppendFormat("第{0}页/共{1}页", currentPage, totalPages);//这个统计加不加都行           if (IsShouCount == true)         {            output.AppendFormat(",共{0}条记录", totalCount);        }        //HtmlString        return output.ToString();    }}

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software