ASPNETPager常用屬性(近來用到分頁屬性)

來源:互聯網
上載者:User

標籤:

ASPNETPager常用屬性

建議去封裝好,然後調用這樣比較容易

<webdiyer:aspnetpager id="AspNetPager1" runat="server"

           alwaysshow="True"

           PageSize="5"

           custominfosectionwidth="20%"

           custominfotextalign="Right"

           firstpagetext="第一頁"

           horizontalalign="Left"

           lastpagetext="末一頁"

           navigationbuttontype="Image" 

           nextpagetext="後一頁"

           pageindexboxtype="TextBox"

           pagingbuttonspacing="8px"

           prevpagetext="前一頁"

           showcustominfosection="Right"

           showpageindexbox="Always"

           textafterpageindexbox="頁"

           UrlPaging="true"

           textbeforepageindexbox="跳到第"

           width="97%"

           onpagechanged="AspNetPager1_PageChanged">

    </webdiyer:aspnetpager>

alwaysshow:總是顯示分頁控制項;

PageSize:指定每頁顯示的記錄數;

custominfosectionwidth:使用者自訂資訊區的寬度;

custominfotextalign:使用者自訂資訊區的對齊;

firstpagetext:第一頁按鈕上顯示的文本;

horizontalalign:內容水平對齊;

lastpagetext:最後頁按鈕上顯示的文本;

navigationbuttontype:第一頁、下一頁、最後一頁按鈕的類型;

nextpagetext:下一頁按鈕上顯示的文本;

pageindexboxtype:指示頁索引框的顯示類型:有TextBOX和dropdownlist兩種;

pagingbuttonspacing:導航頁按鈕的間距;

prevpagetext:上一頁按鈕的顯示的文本;

showcustominfosection:顯示當前頁和總頁資訊,預設為不顯示,值為LEFT時將顯示在頁索引前,為right時顯示在頁索引後;

showpageindexbox:指定頁索引文字框或下拉框的顯示方式;

textafterpageindexbox:指定頁索引文字框或下拉框後的文本;

UrlPaging:是夠使用URL傳遞分頁的方式來分頁;

textbeforepageindexbox:指定頁索引文字框或下拉框前面顯示的文本;

width:該控制項的寬度;

CustomInfoHTML:指定要顯示在使用者自訂資訊區的使用者自訂HTML資訊文本

using System;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        Bind();

    }

    private void Bind()

    {

        int pageindex = 1;

        int pagenum = AspNetPager1.PageSize;

        if (Request["page"] != null)

        {

            pageindex =Convert.ToInt32(Request["page"]);

        }

        DataSet ds = new DataSet();

        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString ());

        SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());

        SqlDataAdapter sda = new SqlDataAdapter("select top (@pagenum) * from pagetest where id not in (select top  (@pagenum*(@pageindex-1)) id from pagetest)", con);

        sda.SelectCommand.Parameters.AddWithValue("pagenum",pagenum);

        sda.SelectCommand.Parameters.AddWithValue("pageindex",pageindex);

        sda.Fill(ds);

        SqlCommand cmd = new SqlCommand("select count(*) from pagetest", con1);

        con1.Open();

        AspNetPager1.RecordCount =Convert.ToInt32(cmd.ExecuteScalar());

        con.Close();

        AspNetPager1.CustomInfoHTML = "共" + AspNetPager1.RecordCount + "條記錄      " + AspNetPager1.CurrentPageIndex + "/" + AspNetPager1.PageCount;

        GridView1.DataSource = ds.Tables[0].DefaultView;

        GridView1.DataBind();

    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)

    {

        Bind();

    }

}

深入分析CurrentPageIndex、RecordCount、 PageCount、 PageSize:

pagecount:

public int PageCount

{

    get

    {

        if (this.RecordCount == 0)

        {

            return 1;

        }

        return (int) Math.Ceiling((double) (((double) this.RecordCount) / ((double) this.PageSize)));

    }

}

recordcount:

public int RecordCount

{

    get

    {

        if (this.cloneFrom != null)

        {

            return this.cloneFrom.RecordCount;

        }

        object obj2 = this.ViewState["Recordcount"];

        if (obj2 != null)

        {

            return (int) obj2;

        }

        return 0;

    }

    set

    {

        this.ViewState["Recordcount"] = value;

    }

}

CurrentPageIndex:

public int CurrentPageIndex

{

    get

    {

        if (this.cloneFrom != null)

        {

            return this.cloneFrom.CurrentPageIndex;

        }

        object obj2 = this.ViewState["CurrentPageIndex"];

        int num = (obj2 == null) ? 1 : ((int) obj2);

        if ((num > this.PageCount) && (this.PageCount > 0))

        {

            return this.PageCount;

        }

        if (num < 1)

        {

            return 1;

        }

        return num;

    }

    set

    {

        int pageCount = value;

        if (pageCount < 1)

        {

            pageCount = 1;

        }

        else if (pageCount > this.PageCount)

        {

            pageCount = this.PageCount;

        }

        this.ViewState["CurrentPageIndex"] = pageCount;

    }

}

PageSize:

public int PageSize

{

    get

    {

        int num;

        if ((!string.IsNullOrEmpty(this.UrlPageSizeName) && !base.DesignMode) && (int.TryParse(this.Page.Request.QueryString[this.UrlPageSizeName], out num) && (num > 0)))

        {

            return num;

        }

        if (this.cloneFrom != null)

        {

            return this.cloneFrom.PageSize;

        }

        object obj2 = this.ViewState["PageSize"];

        if (obj2 != null)

        {

            return (int) obj2;

        }

        return 10;

    }

    set

    {

        this.ViewState["PageSize"] = value;

    }

}

 

 

 

AlwaysShow  

擷取或設定一個值,該值指定是否總是顯示AspNetPager分頁按件,即使要分頁的資料只有一頁。 

CurrentPageButtonPosition  

當前頁數字按鈕在所有數字分頁按鈕中的位置,可選值為:Beginning(最前)、End(最後)、Center(置中)和Fixed(預設固定)   

CurrentPageIndex  

擷取或設定當前顯示頁的索引。   

FirstPageText   

擷取或設定為第一頁按鈕顯示的文本。 

LastPageText   

擷取或設定為最後一頁按鈕顯示的文本。 

NextPageText   

擷取或設定為下一頁按鈕顯示的文本。 

PrevPageText   

擷取或設定為上一頁按鈕顯示的文本。 

PageSize 

  

擷取或設定每頁顯示的項數。(該值擷取或設定資料呈現控制項每次要顯示資料表中的的資料的項數,AspNetPager根據該值和 RecordCount 來計算顯示所有資料需要的總頁數,即 PageCount的值。 )  

 

PageIndexBoxType: 

    

或者或設定頁索引框的顯示類型,可以是允許使用者手工輸入的文字框和只能選擇的下拉框。 

MoreButtonType  

擷取或設定“更多頁”(...)按鈕的類型,該值僅當PagingButtonType設為Image時才有效。 

UrlPageIndexName  

擷取或設定當啟用Url分頁方式時,在url中表示要傳遞的頁索引的參數的名稱。   

UrlPageSizeName  

擷取或設定Url中指定每頁顯示記錄數的參數的名稱,或該值不為空白或Url

 

 

 

 

 

 

中該值對應的參數的值大於0,則PageSize屬性將使用該參數的值做為每頁顯示的記錄數。   

UrlPaging  

擷取或設定是否啟用url來傳遞分頁資訊。  

 

TextAfterPageIndexBox  

擷取或設定頁索引頁索引輸入文字框或下拉框後的文本字串值。   

TextBeforePageIndexBox  

擷取或設定頁索引頁索引輸入文字框或下拉框前的文本字串值。 

NavigationButtonType  

擷取或設定第一頁、上一頁、下一頁和最後一頁按鈕的類型,該值僅當PagingButtonType設為Image時才有效。   

NavigationToolTipTextFormatString  

擷取或設定導覽按鈕工具提示文本的格式。   

NextPageText  

擷取或設定為下一頁按鈕顯示的文本。   

NumericButtonCount  

擷取或設定在 AspNetPager 控制項的頁導航元素中同時顯示的數值按鈕的數目。   

NumericButtonTextFormatString  

擷取或設定頁索引數值導覽按鈕上文本的顯示格式。   

NumericButtonType  

擷取或設定頁導航數值按鈕的類型,該值僅當PagingButtonType設為Image時才有效。  

PageCount  

擷取所有要分頁的記錄需要的總頁數。   

PageIndexBoxClass  

擷取或設定應用於頁索引輸入文字框或下拉框的CSS類名。   

PageIndexBoxStyle  

擷取或設定頁索引輸入文字框或下拉框的CSS樣式文本。   

PageIndexBoxType   

 

 

 

 

 

 

PageIndexOutOfRangeErrorMessage  

擷取或設定當使用者輸入的頁索引超出範圍(大於最大頁索引或小於最小頁索引)時在用戶端顯示的錯誤資訊。   

PageSize 擷取或設定每頁顯示的項數。   

PagesRemain 擷取當前頁之後未顯示的頁的總數。   PagingButtonLayoutType  

指定分頁導覽按鈕(數字和上頁、下頁、首頁、尾頁)布局方式,可以將這些元素包含在<li> 或<span>標籤中以方便應用CSS樣式,預設不包含在任何標籤中。   

PagingButtonSpacing  

擷取或設定分頁導覽按鈕之間的間距。   

PagingButtonType  

擷取或設定分頁導覽按鈕的類型,即使用文字還是圖片。  

ShowFirstLast  

擷取或設定一個值,該值指示是否在頁導航元素中顯示第一頁和最後一頁按鈕。   

ShowNavigationToolTip  

擷取或設定一個值,該值批示當滑鼠指標懸停在導覽按鈕上時是否顯示工具提示。   

ShowPageIndex  

擷取或設定一個值,該值指示是否在頁導航元素中顯示頁索引數值按鈕。   

ShowPageIndexBox   ShowPrevNext  

擷取或設定一個值,該值指示是否在頁導航元素中顯示上一頁和下一頁按鈕

ASPNETPager常用屬性(近來用到分頁屬性)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.