日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

GridView分頁之通用類

 二寶么么噠 2010-12-27
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
/// <summary>
/// GridViewPager 的摘要說明
/// </summary>
public class GridViewPager<T>
{
    public GridViewPager()
    {
        //
        // TODO: 在此處添加構造函數(shù)邏輯
        //
    }
    public static string GetPageNum(IList<T> list, GridView GridViewName, int PageSize)
    {
        int Page = 0, AllPage = 0, Next = 0, Pre = 0, StartCount = 0, EndCount = 0;
        string PageStr = "", QueryStr = "";
        string[] Temp_Arr = null;
        string FilePath = HttpContext.Current.Request.CurrentExecutionFilePath;
        string currentPath = HttpContext.Current.Request.Url.Query;
        //string SelPage = "  轉到<select name=SelPage id=SelPage onchange=\"javascript:location.href=this.value\">";
        int startIndex = currentPath.IndexOf("&");
        int startIndex2 = currentPath.IndexOf("=");
        if (startIndex < 0 && startIndex2 < 0) { QueryStr = "?"; }
        if (startIndex < 0)
        {
            //QueryStr = "?";
            if (startIndex2 > 0)
            {
                Temp_Arr = currentPath.Split('=');
                if (Temp_Arr[0] != "?Page")
                {
                    QueryStr = "";
                    QueryStr = Temp_Arr[0] + "=" + Temp_Arr[1] + "&";
                }
                else
                { QueryStr = "?"; }
            }
        }
        else
        {
            string Temp = null;
            string[] Params_Array = null;
            string[] nameValues = currentPath.Split('&');
            QueryStr = "";
            Temp = "";
            foreach (string param in nameValues)
            {
                if (param.IndexOf("=") > 0)
                {
                    Params_Array = param.Split('=');
                    if (Params_Array[0] != "Page")
                    {
                        Temp += Params_Array[0] + "=" + Params_Array[1] + "&";
                    }
                }
            }
            QueryStr = Temp;
        }
        PagedDataSource ObjPds = new PagedDataSource();
        ObjPds.DataSource = list;
        ObjPds.AllowPaging = true;
        int Total = list.Count;
        ObjPds.PageSize = PageSize;
        if (HttpContext.Current.Request.QueryString["Page"] != null)
        {
            Page = Convert.ToInt32(HttpContext.Current.Request.QueryString["Page"]);
        }
        else
        {
            Page = 1;
        }
        ObjPds.CurrentPageIndex = Page - 1;
        GridViewName.DataSource = ObjPds;
        GridViewName.DataBind();
        if (Page < 1) Page = 1;
        if (PageSize != 0)
        {
            AllPage = (Total / PageSize);
            AllPage = ((Total % PageSize) != 0 ? AllPage + 1 : AllPage);
            AllPage = (AllPage == 0 ? 1 : AllPage);
        }
        Next = Page + 1;
        Pre = Page - 1;
        StartCount = (Page + 5) > AllPage ? AllPage - 9 : Page - 4;  //中間頁起始序號
        EndCount = Page < 5 ? 10 : Page + 5; //中間頁終止序號
        if (StartCount < 1) { StartCount = 1; }//為了避免輸出的時候產生負數(shù),設置如果小于1就從序號1開始
        if (AllPage < EndCount) { EndCount = AllPage; }//頁碼+5的可能性就會產生最終輸出序號大于總頁碼,那么就要將其控制在頁碼數(shù)之內
        PageStr = "共" + AllPage + "頁      ";
        PageStr += Page > 1 ? "<a href=\"" + FilePath + QueryStr + "Page=1\">首頁</a>  <a href=\"" + FilePath + QueryStr + "Page=" + Pre + "\">上一頁</a>" : "首頁 上一頁";
        for (int xk = StartCount; xk < EndCount; xk++)
        {
            PageStr += Page == xk ? "  <font color=\"#ff0000\">" + xk + "</font>" : "  <a href=\"" + FilePath + QueryStr + "Page=" + xk + "\">" + xk + "</a>";
        }
        PageStr += Page != AllPage ? "  <a href=\"" + FilePath + QueryStr + "Page=" + Next + "\">下一頁</a>  <a href=\"" + FilePath + QueryStr + "Page=" + AllPage + "\">末頁</a>" : " 下一頁 末頁  ";
        return PageStr;
    }
}

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多