AJAX实现开源中国分页

/// <summary>
    /// 仿造开源中国的分页,分页界面类似URL分页
    /// 1 [2] [3] [4] [100]
    /// qq:Zr、还有点BUG没修正
    /// <param name="currentIndex">当前索引</param>
    /// <param name="count">页数</param>
    /// <param name="url">跳转的页面</param>
    /// <param name="classname">样式名</param>
    /// <returns></returns>
    public string pagIng(int currentIndex, int count, string url, string classname)
    {
        int rightNum = 11; int step = 3;
        if (step <= 0 || currentIndex <= 0)
        {
            return null;
        }
        int LeftNum = 0; StringBuilder sb = new StringBuilder();
        if (currentIndex - step <= 1)
            LeftNum = 2;
        else
        {
            LeftNum = currentIndex - step;
            rightNum = currentIndex + (2 * step + 1) > count ? count:currentIndex + (2 * step + 1); 
            if (currentIndex + step > count)
            {
                rightNum = count;
            }
        }
        if (rightNum > count)
        {
            rightNum = count;
        }
        sb= currentIndex == 1 ? sb.Append("<span class=/"'" + classname + "'/">" + 1 + "</span>") : sb.Append("<span   class=/"'" + classname + "'/"><a name='" + url + "=1'>[" + 1 + "]</a></span>");
        for (int i = LeftNum; i < rightNum; i++)
        {
            sb = i == currentIndex ? sb.Append("<span class=/"'" + classname + "'/">" + i + "</span>") : sb.Append("<span  class=/"'" + classname + "'/"><a name='" + url + "=" + i + "'>[" + i + "]</a></span>");
        }
        if(count!=1)
        sb = currentIndex == count ? sb.Append("<span class=/"'" + classname + "'/">" + count + "</span>") : sb.Append("<span  class=/"'" + classname + "'/"><a name='" + url + "=" + count + "'>[" + count + "]</a></span>");
        return sb.ToString();
        //Response.End();
    }

这样来调用

  int currentIndex = Convert.ToInt32(Request.QueryString["pid"]);
        int count = c1.bb() % pagesize == 0 ? c1.bb() / pagesize : c1.bb() / pagesize + 1;
       string str= pagIng(currentIndex, count, "?pid", "");

前台就简单了啊

用的JQUERY

$("a").click(function(){
    var pid=$(this).attr("name");
  $(this).css("style","cursor:hand");
    $.get(pid,function(data,state){ $("#DIV1").empty().append(data)});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值