Proprietà DataPager.Fields (System.Web.UI.WebControls)

Cambia visualizzazione:
ScriptFree
Riferimento a .NET Framework
Proprietà DataPager.Fields
Il presente articolo è stato tradotto manualmente. Per visualizzare questa pagina e contemporaneamente visualizzarne il contenuto in lingua inglese, passare alla visualizzazione semplificata.

Ottiene un insieme di oggetti DataPagerField che rappresentano i campi del pager specificati in un controllo DataPager.

Spazio dei nomi:  System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)
Sintassi

Visual Basic
<PersistenceModeAttribute(PersistenceMode.InnerProperty)> _
Public Overridable ReadOnly Property Fields As DataPagerFieldCollection
	Get
C#
[PersistenceModeAttribute(PersistenceMode.InnerProperty)]
public virtual DataPagerFieldCollection Fields { get; }
Visual C++
[PersistenceModeAttribute(PersistenceMode::InnerProperty)]
public:
virtual property DataPagerFieldCollection^ Fields {
	DataPagerFieldCollection^ get ();
}
F#
[<PersistenceModeAttribute(PersistenceMode.InnerProperty)>]
abstract Fields : DataPagerFieldCollection
[<PersistenceModeAttribute(PersistenceMode.InnerProperty)>]
override Fields : DataPagerFieldCollection

Valore proprietà

Tipo: System.Web.UI.WebControls.DataPagerFieldCollection
Oggetto insieme contenente tutti i campi del pager specificati nel controllo DataPager.
Note

I campi del pager vengono visualizzati nel controllo DataPager nello stesso ordine in cui i campi del pager vengono visualizzati nell'insieme Fields. Nella tabella riportata di seguito vengono illustrate le diverse classi di campi del pager che derivano dalla classe DataPagerField e che è possibile utilizzare nell'insieme Fields.

Tipo di campo del pager

Oggetto di descrizione

NextPreviousPagerField

Consente agli utenti di spostarsi tra le pagine di dati una pagina alla volta o di passare alla prima o all'ultima pagina di dati.

NumericPagerField

Consente agli utenti di selezionare una pagina di dati in base al numero di pagina.

TemplatePagerField

Consente di creare un'interfaccia di paging personalizzata.

Per specificare i campi del pager in modo dichiarativo per un controllo DataPager, inserire un elemento Fields all'interno del controllo DataPager. Sarà possibile quindi elencare i campi del pager che si desidera includere tra i tag <Fields> di apertura e di chiusura.

È possibile aggiungere campi del pager all'insieme Fields a livello di codice. È tuttavia più semplice elencare i campi del pager in modo dichiarativo nel controllo DataPager.

Esempi

Nell'esempio di codice riportato di seguito viene illustrato come aggiungere campi del pager in modo dichiarativo all'insieme Fields di un controllo DataPager.

Visual Basic

<%@ 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>


C#

<%@ 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>


Nell'esempio riportato di seguito viene illustrato come utilizzare la proprietà Fields per aggiungere in modo dinamico un oggetto NextPreviousPagerField a un controllo DataPager. Questo esempio di codice fa parte di un esempio più esaustivo fornito per il costruttore NextPreviousPagerField.

Visual Basic

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


C#

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();

}


Informazioni sulla versione

.NET Framework

Supportato in: 4, 3.5
Piattaforme

Windows 7, Windows Vista SP1 o versione successiva, Windows XP SP3, Windows Server 2008 (componenti di base del server non supportati), Windows Server 2008 R2 (componenti di base del server supportati con SP1 o versione successiva), Windows Server 2003 SP2

.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.
Vedere anche

Riferimenti

Altre risorse