共用方式為


PagerSettings.Mode 屬性

定義

取得或設定顯示分頁器控制項的模式,該控制項支援分頁。

public:
 property System::Web::UI::WebControls::PagerButtons Mode { System::Web::UI::WebControls::PagerButtons get(); void set(System::Web::UI::WebControls::PagerButtons value); };
public System.Web.UI.WebControls.PagerButtons Mode { get; set; }
member this.Mode : System.Web.UI.WebControls.PagerButtons with get, set
Public Property Mode As PagerButtons

屬性值

這是其中一項 PagerButtons 價值。 預設值為 PagerButtons.Numeric

例外狀況

Mode 值被設定為非該 PagerButtons 值之一的值。

範例

以下程式碼範例示範如何使用該 Mode 屬性指定控制項的分頁列 GridView 應顯示數字按鈕。


<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>PagerSetting Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>PagerSetting Example</h3>
                       
        <asp:gridview id="CustomerGridView"
          datasourceid="CustomerDataSource"
          autogeneratecolumns="true"
          datakeynames="CustomerID"  
          allowpaging="true"
          runat="server">
          
          <pagersettings mode="NumericFirstLast"
            firstpagetext="First"
            lastpagetext="Last"
            pagebuttoncount="5"  
            position="Bottom"/> 
            
        </asp:gridview>
        
        <br/>
        
        <asp:label id="MessageLabel"
          forecolor="Red"
          runat="server"/>
            
        <!-- This example uses Microsoft SQL Server and connects  -->
        <!-- to the Northwind sample database. Use an ASP.NET     -->
        <!-- expression to retrieve the connection string value   -->
        <!-- from the Web.config file.                            -->
        <asp:sqldatasource id="CustomerDataSource"
          selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
          connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
          runat="server"/>
            
      </form>
  </body>
</html>

<%@ Page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>PagerSetting Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>PagerSetting Example</h3>
                       
        <asp:gridview id="CustomerGridView"
          datasourceid="CustomerDataSource"
          autogeneratecolumns="true"
          datakeynames="CustomerID"  
          allowpaging="true"
          runat="server">
          
          <pagersettings mode="NumericFirstLast"
            firstpagetext="First"
            lastpagetext="Last"
            pagebuttoncount="5"  
            position="Bottom"/> 
            
        </asp:gridview>
        
        <br/>
        
        <asp:label id="MessageLabel"
          forecolor="Red"
          runat="server"/>
            
        <!-- This example uses Microsoft SQL Server and connects  -->
        <!-- to the Northwind sample database. Use an ASP.NET     -->
        <!-- expression to retrieve the connection string value   -->
        <!-- from the Web.config file.                            -->
        <asp:sqldatasource id="CustomerDataSource"
          selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
          connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
          runat="server"/>
            
      </form>
  </body>
</html>

備註

支援分頁的控制項提供多種模式來顯示分頁控制。 使用屬性 Mode 來指定模式。 下表描述分頁控制的不同模式。

模式 說明
NextPrevious 上一頁與下一頁按鈕。
NextPreviousFirstLast 上一頁、下一頁、第一頁和最後一頁按鈕。
Numeric 編號連結按鈕可直接存取頁面。
NumericFirstLast 有編號、第一連結和最後一連結按鈕。

當屬性 Mode 設定為 NextPreviousNextPreviousFirstLastNumericFirstLast 值時,你可以透過下表所示的屬性來指定非數字按鈕的自訂文字。

房產 說明
FirstPageText 首頁按鈕的文字。
PreviousPageText 上一頁按鈕的文字。
NextPageText 下一頁按鈕的文字。
LastPageText 最後一頁按鈕的文字。

另外,你也可以透過設定下表中的屬性,顯示非數字按鈕的圖片。

房產 說明
FirstPageImageUrl 首頁按鈕顯示的圖片網址。
PreviousPageImageUrl 要顯示給上一頁按鈕的圖片網址。
NextPageImageUrl 下一頁按鈕顯示的圖片網址。
LastPageImageUrl 圖片的網址,用於最後一頁按鈕。

備註

當設定了影像屬性時,對應的文字屬性會作為該影像的替代文字。 例如,當設定屬性 FirstPageImageUrl 時,屬性指定的文字 FirstPageText 會顯示為圖片的替代文字。 在支援工具提示的瀏覽器中,該文字也會以對應按鈕的工具提示形式顯示。

此屬性的價值會儲存在視圖狀態。

適用於

另請參閱