public class PageSetting
{
    public static string GetPagestring(int pagecount, string pagename, int pagesize)
    {
        //[1]确定上一页与下一页
        string strpri = "<a href=" + pagename + "?Page=" + (pagesize - 1) + "><FONT color=blue>上一页</font></a>&nbsp;";
        string strnext = "<a href=" + pagename + "?Page=" + (pagesize + 1) + "><FONT color=blue>下一页</font></a>&nbsp;";
        if (pagesize == 1)
        {
            strpri = "";
        }
        if (pagesize == pagecount)
        {
            strnext = "";
        }
        //[2]确定起始页码与终点页码
        int pstart = 1, pend = 10;

        if (pagecount < 10)
        {
            pstart = 1; pend = pagecount;          
        }
        else
        {
            pstart = (pagesize-1) / 10 * 10+1;

            if (pstart + 9 <= pagecount)
            {
                pend = pstart + 9;              
            }
            else
            {
                pend = pagecount;               
            }
        }    
   
        //[3]输出页码
        string outpage = "";
        for (int i = pstart; i <= pend; i++)
        {
            if (i == pagesize)
            {
                outpage += i.ToString() + "&nbsp;";
            }
            else
            {
                outpage += "<a href=" + pagename + "?Page=" + i.ToString() + "><FONT color=blue>[" + i.ToString() + "]</font></a>&nbsp;";
            }
        }
        return strpri + outpage + strnext ;
    }
}

转载于:https://wwwblogs/qinhaijun/archive/2011/08/26/2154432.html

更多推荐

上一页 1 2 3 ... 10 下一页 固定分页