ASP.NET分页技术

自己在做网站时经常使用的一个分页程序,希望大家指点!

 

public static StringBuilder PageBtn(int currentPage, int numInOneLine, string url, PagedDataSource pds)//返回索引字符串,numInOneLine为每行索引的个数,currentPage为当前页;
    {
            StringBuilder sb = new StringBuilder();
            int currentLine; //当前索引行

            if (currentPage % numInOneLine != 0)//判断当前页是否为每行索引的个数的整数倍;
            {
                currentLine= currentPage / numInOneLine + 1;
            }
            else
            {
                currentLine=currentPage / numInOneLine;
            }
            //添加上一索引行连接
            if (currentLine == 1)
            {
                sb.Append("<<&nbsp");
            }
            else
            {
                sb.Append("<a href='");
                sb.Append(url);
                sb.Append("?currentPage=");
                sb.Append(Convert.ToString((currentLine-1)*numInOneLine));
                sb.Append("'><<</a>&nbsp");
            }

            //添加页码索引
            for (int i = 1; i <= numInOneLine; i++)
            {
                //<a href="Datalist.aspx" style="color:Red">[]</a>
                if ((currentLine - 1) * numInOneLine + i<=pds.PageCount)//判断页码是否出界;
                {
                    if ((currentLine - 1) * numInOneLine + i == currentPage)//判断索引页码是否为当前页
                    {
                        sb.Append("&nbsp<font style='color:Red; text-decoration: none;'>");
                        sb.Append(currentPage.ToString());
                        sb.Append("</font>&nbsp");
                    }
                    else
                    {

                        sb.Append("<a href='");
                        sb.Append(url);
                        sb.Append("?currentPage=");
                        sb.Append(Convert.ToString((currentLine - 1) * numInOneLine + i));
                        sb.Append("'>[");
                        sb.Append(Convert.ToString((currentLine - 1) * numInOneLine + i));
                        sb.Append("]</a>&nbsp");
                    }
                }
            }

            int totalLine;//定义总索引行数
            if (pds.PageCount % numInOneLine != 0)//判断总页数是否为每行索引的个数的整数倍;
            {
                totalLine = pds.PageCount / numInOneLine + 1;
            }
            else
            {
                totalLine = pds.PageCount / numInOneLine;
            }
            //添加下一索引行
            if (currentLine == totalLine)
            {
                sb.Append(">>");
            }
            else
            {
                sb.Append("<a href='");
                sb.Append(url);
                sb.Append("?currentPage=");
                sb.Append(Convert.ToString(currentLine * numInOneLine + 1));
                sb.Append("'>>></a>");
            }
       
        return sb;

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值