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)
    *
    */
    
    





  • 相关阅读:
    【C#】往异步下载的方法传递自定义完成事件
    【WPF】CommandParameter解决多传参问题
    【WPF/C#】使用BackgroundWorker实现多线程/异步操作
    【WPF】弹窗定位、弹窗关闭后再打开的报错
    【WPF/C#】测试下载文件(图片)
    【Unity】初始化物体的旋转角度
    【Unity/C#】DateTime时间字符串,月份用英文显示
    【转】【Unity】DateTime各种时间字符串
    【Unity】UGUI无法修改字体大小
    intellij idea运行Android程序时报错;Unable to locate adb within SDK
  • 原文地址:https://www.cnblogs.com/CodeBase/p/2230202.html
Copyright © 2011-2022 走看看