zoukankan      html  css  js  c++  java
  • Cnic.CodeBase.PagingHelper.BuildLinks

            public static string ConcatAnchor(string url, string attr, string queryName, string pageNum, string innerText)
    {
    string[] rtun=new string[10];
    rtun[0]=("<a ");
    rtun[1] = (attr);
    rtun[2] = (" href=\"");
    rtun[3] = (url);
    rtun[4] = (queryName);
    rtun[5] = ("=");
    rtun[6] = (pageNum);
    rtun[7] = ("\">");
    rtun[8] = (innerText);
    rtun[9] = ("</a>\n");
    return String.Concat(rtun);
    }


    /// <summary>
            /// 数字分页
            /// </summary>
            /// <param name="Url">Url链接,此参数要求链接的最后一位字符为&或?</param>
            /// <param name="QueryName">页码参数名称</param>
            /// <param name="PageNum">当前页码,从1开始</param>
            /// <param name="PageTotal">总页数</param>
            /// <param name="LinkSize">显示链接的个数</param>
            /// <param name="DivAttr">Div的属性,可以指定id,此参数可以为为空</param>
            /// <param name="SpanAttr">Span的属性,可以指定id,此参数可以为为空</param>
            /// <param name="AAttr">链接的属性,不可以指定id,此参数可以为为空</param>
            public static string BuildLinks(string Url, string QueryName, int PageNum, int PageTotal, int LinkSize, string DivAttr,string SpanAttr, string AAttr)
    {
    StringBuilder rtun = new StringBuilder();
    rtun.Append("<div ");
    rtun.Append(DivAttr);
    rtun.Append(" >\n");
    int pageNum = PageNum > 0 ? PageNum : 1;
    int pageCount = PageTotal > 0 ? PageTotal : 1;
    if (pageNum > pageCount) { pageNum = pageCount; }
    int linkNum = LinkSize > 0 ? LinkSize : 1;
    int pageStart = ((pageNum - 1) / linkNum) * linkNum + 1;
    int pageEnd = pageStart + linkNum;
    pageEnd = pageEnd > pageCount ? pageCount + 1 : pageEnd;

    rtun.Append(ConcatAnchor(Url, AAttr, QueryName, "1", "首页"));
    if (pageNum > 1)
    {
    rtun.Append(ConcatAnchor(Url, AAttr, QueryName, ((int)(pageNum - 1)).ToString(), "上一页"));
    }
    for (int i = pageStart; i < pageEnd; i++)
    {
    if (i == pageNum)
    {
    rtun.Append("<span "+SpanAttr+" >");
    rtun.Append(i.ToString());
    rtun.Append("</span>\n");
    }
    else
    {
    rtun.Append(ConcatAnchor(Url, AAttr, QueryName, i.ToString(), i.ToString()));
    }
    }
    if (pageNum < pageCount)
    {
    rtun.Append(ConcatAnchor(Url, AAttr, QueryName, ((int)(pageNum+1)).ToString(), "下一页"));
    }
    rtun.Append(ConcatAnchor(Url, AAttr, QueryName, pageCount.ToString(), "末页"));
    rtun.Append("</div>");
    return rtun.ToString();
    }


    /*
    * LZ:
    * BuildLinks("/Ajax.aspx?Action=LoadList&","Page",i,33,10,"id=\"Cnic_Page_Tool\" class=\"PageBar\"","",null)
    *
    */
    
    





  • 相关阅读:
    为什么要做服务化?
    同步 互斥锁 读写锁 区别
    http request header 中的host行的作用
    关于group by 、group by having、where group by与 group by order by
    where,having与 group by连用的区别
    数据库:drop、truncate、delete三者删除的区别
    设置 TOMCAT 请求超时时间 和 最大连接数
    访问平台Servlet时,如何设置超时时间
    开源一款简单清爽的日历组件,JavaScript版的
    关于响应式布局
  • 原文地址:https://www.cnblogs.com/CodeBase/p/2230202.html
Copyright © 2011-2022 走看看