aspnetpager分页控件_如何自动分页

aspnetpager分页控件_如何自动分页AspNetMvc分页控件,可自定义链接地址,开源分亨给大家先看效果图下载DLL文件,使用大家可进入讨论群160046333,进行讨论 一.如果你使用GET方式传递参数如http://www.CSDN.com/indx?id=1&page=5 调用方式如下:CSS样式:.Dcssa{padding:4px8px;border:1pxsolid#9

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

AspNetMvc分页控件,可自定义链接地址,开源分亨给大家

先看效果图

下载DLL文件,使用

大家可进入讨论群160046333,进行讨论

 aspnetpager分页控件_如何自动分页

一.如果你使用GET方式传递参数

http://www.CSDN.com/indx?id=1&page=5

 

调用方式如下:

CSS样式:

.Dcssa{
padding:4px8px;border:1pxsolid#999999;color:#000000;margin-left:1px;}

.Scss{
padding:4px8px;}

控制器:

一:默认显示10个页数

ViewData[“Page”] = newAspNetMvcPage.MVCPage(10, 500, 3, “Dcss”, “Scss”,”page”,).RetureHtml();

二:自定义显示页数的显示个数(20个)
ViewData[“Page”] = new AspNetMvcPage.MVCPage(10, 500, 3,”Dcss”, “Scss”, “page”, 20).RetureHtml();

视图:

<%=ViewData[“Page”] %>

 

构造函数参数说明

       /// <summary>

       /// 默认链接模式(合适Get的URL传递参数模式)

       /// </summary>

       /// <param name=”url”>自定义链接地址</param>

       /// <param name=”Number”>每页显示数</param>

       /// <param name=”Count”>数据总行数</param>

        /// <param name=”Page”>当前页数</param>

       /// <param name=”DClassName”>外观DIV样式(可定义A链接样式)</param>

       /// <param name=”SClassName”>当前选择页样式</param>

       /// <param name=”PageName”>URL分页参数名</param>

       public MVCPage(int Number, int Count, int Page, string DClassName,string SClassName,string PageName)

 

       /// <summary>

       /// 默认链接模式(自定义显示分页的个数,合适Get的URL传递参数模式)

       /// </summary>

       /// <param name=”url”>自定义链接地址</param>

       /// <param name=”Number”>每页显示数</param>

       /// <param name=”Count”>数据总行数</param>

       /// <param name=”Page”>当前页数</param>

       /// <param name=”DClassName”>外观DIV样式(可定义A链接样式)</param>

       /// <param name=”SClassName”>当前选择页样式</param>

       /// <param name=”PageName”>URL分页参数名</param>

       /// <paramname=”ShowPageCount”>显示分页的个数</param>

       public MVCPage(int Number, int Count, int Page, string DClassName,string SClassName, string PageName, int ShowPageCount)

 

 

二 如果你使用自定义路径如

http://www.CSDN/index/1/5

调用方法如下:

CSS样式:

.Dcssa{
padding:4px8px;border:1pxsolid#999999;color:#000000;margin-left:1px;}

.Scss{
padding:4px8px;}

 

控制器:

一:默认显示10个页数

ViewData[“Page”] = newAspNetMvcPage.MVCPage(“http://www.csdn.com/index/@page/5”, 10, 500,3, “Dcss”, “Scss”).RetureHtml();

二:自定义显示页数的显示个数(20个)

ViewData[“Page”] = newAspNetMvcPage.MVCPage(“http://www.csdn.com/index/@page/5”, 10, 500,3, “Dcss”, “Scss”,20).RetureHtml();

视图:

<%=ViewData[“Page”] %>

 

构造函数参数说明

       /// <summary>

       /// 经典模式(自定义链接模式)

       /// </summary>

       /// <param name=”url”>自定义链接地址(页数用@page代替)</param>

       /// <param name=”Number”>每页显示数</param>

       /// <param name=”Count”>数据总行数</param>

       /// <param name=”Page”>当前页数</param>

       /// <param name=”DClassName”>外观DIV样式(可定义A链接样式)</param>

       /// <param name=”SClassName”>当前选择页样式</param>

       public MVCPage(string url,int Number,int Count,int Page,stringDClassName,string SClassName)

 

       /// <summary>

       /// 经典模式(自定义链接,显示分页的个数模式)

       /// </summary>

       /// <param name=”url”>自定义链接地址(页数用@page代替)</param>

       /// <param name=”Number”>每页显示数</param>

       /// <param name=”Count”>数据总行数</param>

       /// <param name=”Page”>当前页数</param>

       /// <param name=”DClassName”>外观DIV样式(可定义A链接样式)</param>

       /// <param name=”SClassName”>当前选择页样式</param>

       /// <param name=”ShowPageCount”>显示分页的个数</param>

       public MVCPage(string url, int Number, int Count, int Page, stringDClassName, string SClassName, int ShowPageCount)

源代码:

namespace AspNetMvcPage
{
    public class MVCPage
    {
        #region 构造函数

        #region 默认链接模式
        /// <summary>
        /// 默认链接模式(合适Get的URL传递参数模式)
        /// </summary>
        /// <param name="url">自定义链接地址</param>
        /// <param name="Number">每页显示数</param>
        /// <param name="Count">数据总行数</param>
        /// <param name="Page">当前页数</param>
        /// <param name="DClassName">外观DIV样式(可定义A链接样式)</param>
        /// <param name="SClassName">当前选择页样式</param>
        /// <param name="PageName">URL分页参数名</param>
        public MVCPage(int Number, int Count, int Page, string DClassName, string SClassName,string PageName)
        {
            this.Number = Number;
            this.Count = Count;
            this.Page = Page;
            this.DClassName = DClassName;
            this.SClassName = SClassName;
            this.PageName = PageName;
            this.IsCustom = false;
        }
        /// <summary>
        /// 默认链接模式(自定义显示分页的个数,合适Get的URL传递参数模式)
        /// </summary>
        /// <param name="url">自定义链接地址</param>
        /// <param name="Number">每页显示数</param>
        /// <param name="Count">数据总行数</param>
        /// <param name="Page">当前页数</param>
        /// <param name="DClassName">外观DIV样式(可定义A链接样式)</param>
        /// <param name="SClassName">当前选择页样式</param>
        /// <param name="PageName">URL分页参数名</param>
        /// <param name="ShowPageCount">显示分页的个数</param>
        public MVCPage(int Number, int Count, int Page, string DClassName, string SClassName, string PageName, int ShowPageCount)
        {
            this.Number = Number;
            this.Count = Count;
            this.Page = Page;
            this.DClassName = DClassName;
            this.SClassName = SClassName;
            this.PageName = PageName;
            this.ShowPageCount = ShowPageCount;
            this.IsCustom = false;
        }
        #endregion

        #region 经典模式(自定义链接模式)
        /// <summary>
        /// 经典模式(自定义链接模式)
        /// </summary>
        /// <param name="url">自定义链接地址(页数用@page代替)</param>
        /// <param name="Number">每页显示数</param>
        /// <param name="Count">数据总行数</param>
        /// <param name="Page">当前页数</param>
        /// <param name="DClassName">外观DIV样式(可定义A链接样式)</param>
        /// <param name="SClassName">当前选择页样式</param>
        public MVCPage(string url,int Number,int Count,int Page,string DClassName,string SClassName)
        {
            this.url = url;
            this.Number = Number;
            this.Count = Count;
            this.Page = Page;
            this.DClassName = DClassName;
            this.SClassName = SClassName;
        }
        /// <summary>
        /// 经典模式(自定义链接,显示分页的个数模式)
        /// </summary>
        /// <param name="url">自定义链接地址(页数用@page代替)</param>
        /// <param name="Number">每页显示数</param>
        /// <param name="Count">数据总行数</param>
        /// <param name="Page">当前页数</param>
        /// <param name="DClassName">外观DIV样式(可定义A链接样式)</param>
        /// <param name="SClassName">当前选择页样式</param>
        /// <param name="ShowPageCount">显示分页的个数</param>
        public MVCPage(string url, int Number, int Count, int Page, string DClassName, string SClassName, int ShowPageCount)
        {
            this.url = url;
            this.Number = Number;
            this.Count = Count;
            this.Page = Page;
            this.DClassName = DClassName;
            this.SClassName = SClassName;
            this.ShowPageCount = ShowPageCount;
        }
        #endregion

        #endregion

        #region 参数
        private string url = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
        private int Number = 1;
        private int Count = 1;
        private int Page = 1;
        private string DClassName = "";
        private string SClassName = "";
        private string PageName = "@Page";
        private int ShowPageCount = 10;
        private bool IsCustom = true;
        #endregion

        #region 返回分页HTML代码
        public string RetureHtml()
        {
            int PageCount = Count % Number == 0 ? Convert.ToInt32(Count / Number) : Convert.ToInt32(Count / Number) + 1;
            int ShowPageCount = Convert.ToInt32(this.ShowPageCount / 2);
            url = url.ToLower();
            PageName = PageName.ToLower();
            if (IsCustom == false)
            {
                url = url + "?";
                for (int i = 0; i < HttpContext.Current.Request.QueryString.Count; i++)
                {
                    if (HttpContext.Current.Request.QueryString.AllKeys[i] != PageName)
                        url = url + HttpContext.Current.Request.QueryString.AllKeys[i] +"="+ HttpContext.Current.Request.QueryString[i]+"&";
                }
                url = url + PageName + "=";
            }
            StringBuilder str = new StringBuilder();
            if (Page >= 1 && Page <= PageCount)
            {
                if (Number < Count)
                {
                    str.Append("<div class=\"" + DClassName + "\">");
                    if (Page > ShowPageCount && PageCount > this.ShowPageCount)
                        str.Append("<a href=\"" + (IsCustom == true ? url.Replace(PageName, "1") : (url + "1")) + "\">1</a>");
                    if (Page > ShowPageCount && PageCount > this.ShowPageCount)
                    {
                        str.Append("<a href=\"" + (IsCustom == true ? url.Replace(PageName, (Page - ShowPageCount).ToString()) : (url + (Page - ShowPageCount))) + "\">...</a>");
                    }

                    if (PageCount <= this.ShowPageCount)
                    {
                        for (int i = 1; i <= PageCount; i++)
                        {
                            if (i != Page)
                                str.Append("<a href=\"" + (IsCustom == true ? url.Replace(PageName, i.ToString()) : (url + i)) + "\">" + i + "</a>");
                            else
                                str.Append("<span class=\"" + SClassName + "\">" + i + "</span>");
                        }
                    }
                    else
                    {
                        if (Page <= ShowPageCount || Page >= (PageCount - ShowPageCount))
                        {
                            if (Page <= ShowPageCount)
                            {
                                for (int i = 1; i <= this.ShowPageCount; i++)
                                {
                                    if (i != Page)
                                        str.Append("<a href=\"" + (IsCustom == true ? url.Replace(PageName, i.ToString()) : (url + i)) + "\">" + i + "</a>");
                                    else
                                        str.Append("<span class=\"" + SClassName + "\">" + i + "</span>");
                                }
                            }
                            else
                            {
                                for (int i = 1; i <= this.ShowPageCount; i++)
                                {
                                    if (i != this.ShowPageCount - (PageCount - Page))
                                        str.Append("<a href=\"" + (IsCustom == true ? url.Replace(PageName, (PageCount - this.ShowPageCount + i).ToString()) : (url + (PageCount - this.ShowPageCount + i))) + "\">" + (PageCount - this.ShowPageCount + i) + "</a>");
                                    else
                                        str.Append("<span class=\"" + SClassName + "\">" + Page + "</span>");
                                }
                            }
                        }
                        else
                        {
                            for (int i = 1; i <= this.ShowPageCount; i++)
                            {
                                if (i != ShowPageCount)
                                    str.Append("<a href=\"" + (IsCustom == true ? url.Replace(PageName, (Page - ShowPageCount + i).ToString()) : (url + (Page - ShowPageCount + i))) + "\">" + (Page - ShowPageCount + i) + "</a>");
                                else
                                    str.Append("<span class=\"" + SClassName + "\">" + Page + "</span>");
                            }
                        }
                    }


                    if (PageCount - Page > ShowPageCount && PageCount > this.ShowPageCount)
                    {
                        str.Append("<a href=\"" + (IsCustom == true ? url.Replace(PageName, (Page + ShowPageCount).ToString()) : (url + (Page + ShowPageCount))) + "\">...</a>");
                    }
                    if (PageCount - Page > ShowPageCount && PageCount > this.ShowPageCount)
                        str.Append("<a href=\"" + (IsCustom == true ? url.Replace(PageName, PageCount.ToString()) : (url + PageCount)) + "\">" + PageCount + "</a>");

                    str.Append("</div>");
                }
                else
                {
                    str.Append("<div class=\"" + DClassName + "\">");
                    str.Append("<span class=\"" + SClassName + "\">1</span>");
                    str.Append("</div>");
                }
            }
            return str.ToString();
        }
        #endregion
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/187982.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号