怎么在asp.net項(xiàng)目中實(shí)現(xiàn)一個(gè)分頁(yè)功能-創(chuàng)新互聯(lián)

怎么在asp.net項(xiàng)目中實(shí)現(xiàn)一個(gè)分頁(yè)功能?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。

成都創(chuàng)新互聯(lián) - 服務(wù)器機(jī)柜租賃,四川服務(wù)器租用,成都服務(wù)器租用,四川網(wǎng)通托管,綿陽(yáng)服務(wù)器托管,德陽(yáng)服務(wù)器托管,遂寧服務(wù)器托管,綿陽(yáng)服務(wù)器托管,四川云主機(jī),成都云主機(jī),西南云主機(jī),服務(wù)器機(jī)柜租賃,西南服務(wù)器托管,四川/成都大帶寬,機(jī)柜大帶寬租用·托管,四川老牌IDC服務(wù)商

具體實(shí)現(xiàn)方法如下:


復(fù)制代碼 代碼如下:

/// <summary>
/// 分頁(yè)內(nèi)容
/// </summary>
/// <param name="size">頁(yè)面大小</param>
/// <param name="count">頁(yè)面數(shù)量</param>
/// <param name="currendIndex">當(dāng)前頁(yè)</param>
/// <param name="pattern">url模式:demo.aspx?page={0}</param>
/// <param name="target">窗口模式</param>
/// <returns></returns>
public static string get_pagenation(int size,
                                    int count,
                                    int currendIndex,
                                    string pattern,
                                    string target)
{
    //1>打開(kāi)窗口目標(biāo)
    target = string.IsNullOrEmpty(target) ? "_top" : target;
    //2>總頁(yè)數(shù)
    int pageCount = count / size;
    pageCount = pageCount * size == count ? pageCount : pageCount + 1;
    //3>分頁(yè)內(nèi)容
    StringBuilder strHtml = new StringBuilder();
    strHtml.Append("<span class='pagenation'>");
 
    #region 首部處理
    if (currendIndex > 1)
    {
        strHtml.AppendFormat("<a href='1' target='{0}'>[首頁(yè)]</a>", target);
        strHtml.AppendFormat("<a href='{0}' target='{1}'>[上一頁(yè)]</a>", string.Format(pattern, currendIndex - 1), target);
    }
    else
    {
        strHtml.Append("<span class='disabled'>[首頁(yè)]</span>&nbsp;&nbsp;<span class='disabled'>[上一頁(yè)]</span>");
    }
    #endregion
 
    #region 中間部分
    int i = 1;
 
    int right = (currendIndex + 4) > pageCount ? pageCount : currendIndex + 4;
    if (currendIndex > 6)
    {
        i = currendIndex - 5;
    }
    else
    {
        right = pageCount >= 10 ? 10 : pageCount;
    }
    for (; i <= right; i++)
    {
        if (i == currendIndex)
        {
            strHtml.AppendFormat("<font class='current'>{0}</font>", i);
            strHtml.AppendLine();
            continue;
        }
        strHtml.AppendFormat("<a href='{0}' target='{1}'>[{2}]</a>", string.Format(pattern, i), target, i);
        strHtml.AppendLine();
    }
    #endregion
 
    #region 尾部處理
    if (currendIndex == pageCount)
    {
        strHtml.Append("<span class='disabled'>[下一頁(yè)]</span><span class='disabled'>[末頁(yè)]</span>");
        strHtml.AppendFormat("總共({0})頁(yè)", pageCount);
    }
    else
    {
        strHtml.AppendFormat("<a href='{0}' target='{1}'>[下一頁(yè)]</a>", string.Format(pattern, currendIndex + 1), target);
        strHtml.AppendFormat("<a href='{0}' target='{1}'>[末頁(yè)]</a>", string.Format(pattern, pageCount), target);
        strHtml.AppendFormat("&nbsp;&nbsp;<label>總共({0})頁(yè)</label>", pageCount);
    }
    #endregion
 
    strHtml.Append("</span>");
 
    return strHtml.ToString();
}

看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,的支持。

網(wǎng)頁(yè)題目:怎么在asp.net項(xiàng)目中實(shí)現(xiàn)一個(gè)分頁(yè)功能-創(chuàng)新互聯(lián)
分享鏈接:http://bm7419.com/article34/geepe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)網(wǎng)站設(shè)計(jì)、域名注冊(cè)微信公眾號(hào)、做網(wǎng)站定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化