DataPager.Fields プロパティ

定義

DataPagerField コントロールに指定されたページャー フィールドを表す DataPager オブジェクトのコレクションを取得します。

public:
 virtual property System::Web::UI::WebControls::DataPagerFieldCollection ^ Fields { System::Web::UI::WebControls::DataPagerFieldCollection ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public virtual System.Web.UI.WebControls.DataPagerFieldCollection Fields { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.Fields : System.Web.UI.WebControls.DataPagerFieldCollection
Public Overridable ReadOnly Property Fields As DataPagerFieldCollection

プロパティ値

DataPager コントロールに指定されたすべてのページャー フィールドが含まれるコレクション オブジェクト。

属性

次の例は、ページャー フィールドをコントロールのコレクションに宣言的に追加する Fields 方法を DataPager 示しています。

<%@ 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 id="Head1" runat="server">
    <title>DataPagerField Example</title>    
    <style type="text/css">
      body  
      {
        text-align: center; 
        font: 13px Tahoma, Arial, Helvetica;
      }
      .item
      {
        border-bottom: solid 1px #FFA500;
        font-weight:bold;
      }
    </style>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>DataPagerField Example</h3>
          
      <asp:ListView ID="ProductsListView" 
        DataSourceID="ContactsDataSource"
        runat="server">
        <LayoutTemplate>
          <table runat="server" id="tblProducts" width="350">
            <tr runat="server" id="itemPlaceholder" />
          </table>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td class="item">
              <asp:Label ID="NameLabel" runat="server" 
                Text='<%#Eval("Name") %>' />
            </td>
          </tr>
          <tr runat="server">
            <td>
              <asp:Label ID="DescriptionLabel" runat="server" 
                Text='<%#Eval("Description")%>' />
            </td>
          </tr>
        </ItemTemplate>
        <ItemSeparatorTemplate>
          <tr runat="server">
            <td>&nbsp;</td>
          </tr>
        </ItemSeparatorTemplate>
      </asp:ListView>
      <br />

      <asp:DataPager runat="server" 
        ID="ProductsDataPager" 
        PageSize="5"
        PagedControlID="ProductsListView">
        <Fields>
          <asp:TemplatePagerField>
            <PagerTemplate>
            <b>
            Page
            <asp:Label runat="server" ID="CurrentPageLabel" 
              Text="<%# Container.TotalRowCount>0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0 %>" />
            of
            <asp:Label runat="server" ID="TotalPagesLabel" 
              Text="<%# Math.Ceiling ((double)Container.TotalRowCount / Container.PageSize) %>" />
            </b>
            <br /><br />
            </PagerTemplate>
          </asp:TemplatePagerField>
          
          <asp:NextPreviousPagerField
            ShowFirstPageButton="true"
            ShowNextPageButton="false"
            ShowPreviousPageButton="false" />
          
          <asp:NumericPagerField 
            PreviousPageText="&lt;&lt;"
            NextPageText="&gt;&gt;"
            ButtonCount="10" />
            
          <asp:NextPreviousPagerField
            ShowLastPageButton="true"
            ShowNextPageButton="false"
            ShowPreviousPageButton="false" />
        </Fields>
      </asp:DataPager>

      <!-- This example uses Microsoft SQL Server and connects      -->
      <!-- to the AdventureWorks sample database. Use an ASP.NET    -->
      <!-- expression to retrieve the connection string value       -->
      <!-- from the Web.config file.                                -->
      <asp:SqlDataSource ID="ContactsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT P.Name, PD.Description 
                      FROM Production.ProductModel AS PM 
                      INNER JOIN Production.Product AS P ON PM.ProductModelID = P.ProductModelID 
                      INNER JOIN Production.ProductModelProductDescriptionCulture AS PMPDC 
                      ON PM.ProductModelID = PMPDC.ProductModelID 
                      INNER JOIN Production.ProductDescription AS PD 
                      ON PMPDC.ProductDescriptionID = PD.ProductDescriptionID 
                      WHERE (PMPDC.CultureID = 'en')">
      </asp:SqlDataSource>
      
    </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 id="Head1" runat="server">
    <title>DataPagerField Example</title>    
    <style type="text/css">
      body  
      {
        text-align: center; 
        font: 13px Tahoma, Arial, Helvetica;
      }
      .item
      {
        border-bottom: solid 1px #FFA500;
        font-weight:bold;
      }
    </style>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>DataPagerField Example</h3>
          
      <asp:ListView ID="ProductsListView" 
        DataSourceID="ContactsDataSource"
        runat="server">
        <LayoutTemplate>
          <table runat="server" id="tblProducts" width="350">
            <tr runat="server" id="itemPlaceholder" />
          </table>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td class="item">
              <asp:Label ID="NameLabel" runat="server" 
                Text='<%#Eval("Name") %>' />
            </td>
          </tr>
          <tr runat="server">
            <td>
              <asp:Label ID="DescriptionLabel" runat="server" 
                Text='<%#Eval("Description")%>' />
            </td>
          </tr>
        </ItemTemplate>
        <ItemSeparatorTemplate>
          <tr runat="server">
            <td>&nbsp;</td>
          </tr>
        </ItemSeparatorTemplate>
      </asp:ListView>
      <br />

      <asp:DataPager runat="server" 
        ID="ProductsDataPager" 
        PageSize="5"
        PagedControlID="ProductsListView">
        <Fields>
          <asp:TemplatePagerField>
            <PagerTemplate>
            <b>
            Page
            <asp:Label runat="server" ID="CurrentPageLabel" 
              Text="<%# IIf(Container.TotalRowCount>0, (Container.StartRowIndex / Container.PageSize) + 1, 0) %>" />
            of
            <asp:Label runat="server" ID="TotalPagesLabel" 
              Text="<%# Math.Ceiling (System.Convert.ToDouble(Container.TotalRowCount) / Container.PageSize) %>" />
            </b>
            <br /><br />            
            </PagerTemplate>
          </asp:TemplatePagerField>
          
          <asp:NextPreviousPagerField
            ShowFirstPageButton="true"
            ShowNextPageButton="false"
            ShowPreviousPageButton="false" />
          
          <asp:NumericPagerField 
            PreviousPageText="&lt;&lt;"
            NextPageText="&gt;&gt;"
            ButtonCount="10" />
            
          <asp:NextPreviousPagerField
            ShowLastPageButton="true"
            ShowNextPageButton="false"
            ShowPreviousPageButton="false" />
        </Fields>
      </asp:DataPager>

      <!-- This example uses Microsoft SQL Server and connects      -->
      <!-- to the AdventureWorks sample database. Use an ASP.NET    -->
      <!-- expression to retrieve the connection string value       -->
      <!-- from the Web.config file.                                -->
      <asp:SqlDataSource ID="ContactsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT P.Name, PD.Description 
                      FROM Production.ProductModel AS PM 
                      INNER JOIN Production.Product AS P ON PM.ProductModelID = P.ProductModelID 
                      INNER JOIN Production.ProductModelProductDescriptionCulture AS PMPDC 
                      ON PM.ProductModelID = PMPDC.ProductModelID 
                      INNER JOIN Production.ProductDescription AS PD 
                      ON PMPDC.ProductDescriptionID = PD.ProductDescriptionID 
                      WHERE (PMPDC.CultureID = 'en')">
      </asp:SqlDataSource>
      
    </form>
  </body>
</html>

次の例では、 プロパティを使用してオブジェクトを Fields コントロールに動的に追加 NextPreviousPagerField する方法を DataPager 示します。 このコード例は、コンストラクターに対して提供されるより大きな例の NextPreviousPagerField 一部です。

void Page_Load(Object sender, EventArgs e)
{
  
  // Dynamically generated field pagers need to be created only 
  // the first time the page is loaded.
  
  if (!IsPostBack)
  {
    // Create a NextPreviousPagerField object to display
    // the buttons to navigate.
    NextPreviousPagerField pagerField = new NextPreviousPagerField();
    pagerField.ShowFirstPageButton = true;
    pagerField.ShowLastPageButton = true;
    pagerField.ButtonType = ButtonType.Button;

    // Add the pager field to the Fields collection of the
    // DataPager control.
    ContactsDataPager.Fields.Add(pagerField);
  }

  ContactsListView.DataBind();

}
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
  
  ' Dynamically generated field pagers need to be created only 
  ' the first time the page is loaded.

  If Not IsPostBack Then
    ' Create a NextPreviousPagerField object to display
    ' the buttons to navigate.
    Dim pagerField As New NextPreviousPagerField()
    pagerField.ShowFirstPageButton = True
    pagerField.ShowLastPageButton = True
    pagerField.ButtonType = ButtonType.Button

    ' Add the pager field to the Fields collection of the
    ' DataPager control.
    ContactsDataPager.Fields.Add(pagerField)
  End If
      
  ContactsListView.DataBind()

End Sub

注釈

ポケットベル フィールドは、コレクションに DataPager ページャー フィールドが表示される順序でコントロールに Fields 表示されます。 次の表は、 クラスから DataPagerField 派生し、コレクションで使用できるポケットベル フィールド クラスを Fields 示しています。

ポケットベル フィールドの種類 [説明]
NextPreviousPagerField ユーザーが一度に 1 ページずつデータのページ間を移動したり、データの最初または最後のページにジャンプしたりできます。
NumericPagerField ユーザーがページ番号でデータのページを選択できるようにします。
TemplatePagerField カスタム ページング UI を作成できます。

コントロールのポケットベル フィールドDataPagerを宣言的に指定するには、コントロール内に 要素をDataPagerFields配置します。 その後、開始タグと終了 <Fields> タグの間に含めるポケットベル フィールドを一覧表示できます。

プログラムを使用して、コレクションにポケットベル フィールドを Fields 追加できます。 ただし、コントロール内で宣言的にポケットベル フィールドを一覧表示する方が DataPager 簡単です。

適用対象

こちらもご覧ください