TemplatePagerField Clase

Definición

Representa un campo DataPager que permite crear una interfaz de usuario de paginación personalizada.

public ref class TemplatePagerField : System::Web::UI::WebControls::DataPagerField
public class TemplatePagerField : System.Web.UI.WebControls.DataPagerField
type TemplatePagerField = class
    inherit DataPagerField
Public Class TemplatePagerField
Inherits DataPagerField
Herencia
TemplatePagerField

Ejemplos

En el ejemplo siguiente se muestra cómo agregar un TemplatePagerField campo en un DataPager control . En este ejemplo se usa TemplatePagerField para mostrar el número de página actual, el número total de páginas y el número total de registros. El DataPager control también contiene dos NextPreviousPagerField campos y un NumericPagerField campo para mostrar controles de navegación que permiten a los usuarios paginar a través de datos.

<%@ 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>TemplatePagerField Example</title>    
    <style type="text/css">
      body 	
      {
        text-align: center;
        font: 12px Arial, Helvetica, sans-serif;
      }
      .item
      {
        border: solid 1px #458b74;
        background: #e0ffff;
      }
    </style>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>TemplatePagerField Example</h3>
          
      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource"
        runat="server">
        <LayoutTemplate>
          <table runat="server" id="tblContacts" width="350">
            <tr id="itemPlaceholder" runat="server">
            </tr>
          </table>
         </LayoutTemplate>
         <ItemTemplate>
            <tr runat="server">
              <td class="item">
                <asp:Label ID="IDLabel" runat="server" Text='<%#Eval("ContactID") %>' />
              </td>            
              <td align="left" class="item">
                <asp:Label ID="NameLabel" runat="server" 
                  Text='<%#Eval("LastName") + ", " + Eval("FirstName")%>' />
              </td>
            </tr>
          </ItemTemplate>
      </asp:ListView>
      <br />

      <asp:DataPager runat="server" 
        ID="ContactsDataPager" 
        PageSize="20"          
        PagedControlID="ContactsListView">
        <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) %>" />
            (
            <asp:Label runat="server" ID="TotalItemsLabel" 
              Text="<%# Container.TotalRowCount%>" />
            records)
            <br />
            </b>
            </PagerTemplate>
          </asp:TemplatePagerField>
          
          <asp:NextPreviousPagerField
            ButtonType="Button"
            ShowFirstPageButton="true"
            ShowNextPageButton="false"
            ShowPreviousPageButton="false" />
          
          <asp:NumericPagerField 
            PreviousPageText="< Prev 10"
            NextPageText="Next 10 >"
            ButtonCount="10" />
            
          <asp:NextPreviousPagerField
            ButtonType="Button"
            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 [ContactID], [FirstName], [LastName] 
          FROM Person.Contact">
      </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>TemplatePagerField Example</title>    
    <style type="text/css">
      body 	
      {
        text-align: center;
        font: 12px Arial, Helvetica, sans-serif;
      }
      .item
      {
        border: solid 1px #458b74;
        background: #e0ffff;
      }
    </style>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>TemplatePagerField Example</h3>
          
      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource"
        runat="server">
        <LayoutTemplate>
          <table runat="server" id="tblContacts" width="350">
            <tr id="itemPlaceholder" runat="server">
            </tr>
          </table>
         </LayoutTemplate>
         <ItemTemplate>
            <tr runat="server">
              <td class="item">
                <asp:Label ID="IDLabel" runat="server" Text='<%#Eval("ContactID") %>' />
              </td>            
              <td align="left" class="item">
                <asp:Label ID="NameLabel" runat="server" 
                  Text='<%#Eval("LastName") & ", " & Eval("FirstName")%>' />
              </td>
            </tr>
          </ItemTemplate>
      </asp:ListView>
      <br />

      <asp:DataPager runat="server" 
        ID="ContactsDataPager" 
        PageSize="20"          
        PagedControlID="ContactsListView">
        <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) %>" />
            (
            <asp:Label runat="server" ID="TotalItemsLabel" 
              Text="<%# Container.TotalRowCount%>" />
            records)
            <br />
            </b>
            </PagerTemplate>
          </asp:TemplatePagerField>
          
          <asp:NextPreviousPagerField
            ButtonType="Button"
            ShowFirstPageButton="true"
            ShowNextPageButton="false"
            ShowPreviousPageButton="false" />
          
          <asp:NumericPagerField 
            PreviousPageText="< Prev 10"
            NextPageText="Next 10 >"
            ButtonCount="10" />
            
          <asp:NextPreviousPagerField
            ButtonType="Button"
            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 [ContactID], [FirstName], [LastName] 
          FROM Person.Contact">
      </asp:SqlDataSource>
      
    </form>
  </body>
</html>

En el ejemplo siguiente se muestra cómo usar el PagerCommand evento para realizar una acción diferente en función del botón en el que se hizo clic en un TemplatePagerField campo. En este ejemplo se usa para TemplatePagerField mostrar controles de navegación que permiten a los usuarios paginar a través de datos.

<%@ Page language="C#" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
<script runat="server">

  // <Snippet2>  
  protected void TemplatePagerField_OnPagerCommand(object sender, DataPagerCommandEventArgs e)
  { 
    // Check which button raised the event
    switch(e.CommandName)
    {
      case "Next":
        int newIndex = e.Item.Pager.StartRowIndex + e.Item.Pager.PageSize;
        if (newIndex <= e.TotalRowCount)
        {
          e.NewStartRowIndex = newIndex;
          e.NewMaximumRows = e.Item.Pager.MaximumRows;
        }
        break;
      case "Previous":
        e.NewStartRowIndex = e.Item.Pager.StartRowIndex - e.Item.Pager.PageSize;
        e.NewMaximumRows = e.Item.Pager.MaximumRows;
        break;
      case "First":
        e.NewStartRowIndex = 0;
        e.NewMaximumRows = e.Item.Pager.MaximumRows;
        break;
    }
  }
  // </Snippet2>
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>TemplatePagerField.OnPagerCommand Example</title>    
    <style type="text/css">
      body 	
      {
        text-align: center;
        font: 12px Arial, Helvetica, sans-serif;
      }
      .item
      {
        border: solid 1px #2F4F4F;
        background: #E6E6FA;
      }
    </style>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>TemplatePagerField.OnPagerCommand Example</h3>
          
      <asp:ListView ID="StoresListView" 
        DataSourceID="StoresDataSource"
        runat="server">
        <LayoutTemplate>
          <table width="350" runat="server" id="tblStore">
            <tr runat="server">
              <th runat="server">ID</th>
              <th runat="server">Store Name</th>
            </tr>
            <tr id="itemPlaceholder" runat="server">
            </tr>
          </table>
         </LayoutTemplate>
         <ItemTemplate>
          <tr runat="server">
            <td class="item">
              <asp:Label ID="IDLabel" runat="server" Text='<%#Eval("CustomerID") %>' />
            </td>            
            <td align="left" class="item">
              <asp:Label ID="NameLabel" runat="server" Text='<%#Eval("Name")%>' />
            </td>
          </tr>
        </ItemTemplate>
      </asp:ListView>
      <br />
      
      <asp:DataPager runat="server" 
        ID="ContactsDataPager" 
        PageSize="30"
        PagedControlID="StoresListView">
        <Fields>
          <asp:TemplatePagerField OnPagerCommand="TemplatePagerField_OnPagerCommand">
            <PagerTemplate> 
              <asp:LinkButton ID="FirstButton" runat="server" CommandName="First" 
                Text="<<" Enabled='<%# Container.StartRowIndex > 0 %>' />
              <asp:LinkButton ID="PreviousButton" runat="server" CommandName="Previous" 
                Text='<%# (Container.StartRowIndex - Container.PageSize + 1) + " - " + (Container.StartRowIndex) %>'
                Visible='<%# Container.StartRowIndex > 0 %>' />
              <asp:Label ID="CurrentPageLabel" runat="server"
                Text='<%# (Container.StartRowIndex + 1) + "-" + (Container.StartRowIndex + Container.PageSize > Container.TotalRowCount ? Container.TotalRowCount : Container.StartRowIndex + Container.PageSize) %>' />
              <asp:LinkButton ID="NextButton" runat="server" CommandName="Next"
                Text='<%# (Container.StartRowIndex + Container.PageSize + 1) + " - " + (Container.StartRowIndex + Container.PageSize*2 > Container.TotalRowCount ? Container.TotalRowCount : Container.StartRowIndex + Container.PageSize*2) %>' 
                Visible='<%# (Container.StartRowIndex + Container.PageSize) < Container.TotalRowCount %>' />
            </PagerTemplate>
          </asp:TemplatePagerField>
        </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="StoresDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
            SelectCommand="SELECT [CustomerID], [Name] FROM Sales.Store ORDER BY [Name]">
      </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">
    
<script runat="server">

  ' <Snippet2>  
  Protected Sub TemplatePagerField_OnPagerCommand(ByVal sender As Object, _
    ByVal e As DataPagerCommandEventArgs)
    
    ' Check which button raised the event
    Select Case e.CommandName
      
      Case "Next"
        Dim newIndex As Integer = e.Item.Pager.StartRowIndex + e.Item.Pager.PageSize
        If newIndex <= e.TotalRowCount Then
          e.NewStartRowIndex = newIndex
          e.NewMaximumRows = e.Item.Pager.MaximumRows
        End If
        
      Case "Previous"
        e.NewStartRowIndex = e.Item.Pager.StartRowIndex - e.Item.Pager.PageSize
        e.NewMaximumRows = e.Item.Pager.MaximumRows
        
      Case "First"
        e.NewStartRowIndex = 0
        e.NewMaximumRows = e.Item.Pager.MaximumRows
        
    End Select
  
  End Sub
  ' </Snippet2>
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>TemplatePagerField.OnPagerCommand Example</title>    
    <style type="text/css">
      body 	
      {
        text-align: center;
        font: 12px Arial, Helvetica, sans-serif;
      }
      .item
      {
        border: solid 1px #2F4F4F;
        background: #E6E6FA;
      }
    </style>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>TemplatePagerField.OnPagerCommand Example</h3>
          
      <asp:ListView ID="StoresListView" 
        DataSourceID="StoresDataSource"
        runat="server">
        <LayoutTemplate>
          <table width="350" runat="server" id="tblStore">
            <tr runat="server">
              <th runat="server">ID</th>
              <th runat="server">Store Name</th>
            </tr>
            <tr id="itemPlaceholder" runat="server">
            </tr>
          </table>
         </LayoutTemplate>
         <ItemTemplate>
          <tr runat="server">
            <td class="item">
              <asp:Label ID="IDLabel" runat="server" Text='<%#Eval("CustomerID") %>' />
            </td>            
            <td align="left" class="item">
              <asp:Label ID="NameLabel" runat="server" Text='<%#Eval("Name")%>' />
            </td>
          </tr>
        </ItemTemplate>
      </asp:ListView>
      <br />
      
      <asp:DataPager runat="server" 
        ID="ContactsDataPager" 
        PageSize="30"
        PagedControlID="StoresListView">
        <Fields>
          <asp:TemplatePagerField OnPagerCommand="TemplatePagerField_OnPagerCommand">
            <PagerTemplate> 
              <asp:LinkButton ID="FirstButton" runat="server" CommandName="First" 
                Text="<<" Enabled='<%# Container.StartRowIndex > 0 %>' />
              <asp:LinkButton ID="PreviousButton" runat="server" CommandName="Previous" 
                Text='<%# (Container.StartRowIndex - Container.PageSize + 1) & " - " & (Container.StartRowIndex) %>'
                Visible='<%# Container.StartRowIndex > 0 %>' />
              <asp:Label ID="CurrentPageLabel" runat="server"
                Text='<%# (Container.StartRowIndex + 1) & "-" & (IIf(Container.StartRowIndex + Container.PageSize > Container.TotalRowCount, Container.TotalRowCount, Container.StartRowIndex + Container.PageSize)) %>' />
              <asp:LinkButton ID="NextButton" runat="server" CommandName="Next"
                Text='<%# (Container.StartRowIndex + Container.PageSize + 1) & " - " & (IIf(Container.StartRowIndex + Container.PageSize*2 > Container.TotalRowCount, Container.TotalRowCount, Container.StartRowIndex + Container.PageSize*2)) %>' 
                Visible='<%# (Container.StartRowIndex + Container.PageSize) < Container.TotalRowCount %>' />
            </PagerTemplate>
          </asp:TemplatePagerField>
        </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="StoresDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
            SelectCommand="SELECT [CustomerID], [Name] FROM Sales.Store ORDER BY [Name]">
      </asp:SqlDataSource>
      
    </form>
  </body>
</html>

Comentarios

Use el TemplatePagerField objeto para mostrar controles de navegación que permiten a los usuarios paginar a través de datos que se muestran mediante un control que implementa la IPageableItemContainer interfaz. (Un ejemplo es el ListView control). También puede usar el TemplatePagerField objeto para mostrar información sobre el origen de datos subyacente, como el número total de registros y el número de página actual.

El TemplatePagerField campo no tiene ningún diseño integrado. Por lo tanto, debe crear explícitamente el diseño en la PagerTemplate plantilla. Puede dar formato al contenido mediante clases de hojas de estilos en cascada (CSS) o elementos de estilo insertados.

Puede hacer referencia al DataPager control que contiene el TemplatePagerField objeto mediante la Container propiedad . Esto resulta útil cuando desea crear expresiones de enlace para mostrar cuántos registros se recuperaron, el número total de páginas y información similar. Estas expresiones de enlace pueden usar propiedades del DataPager control como MaximumRows, PageSize, StartRowIndexy TotalRowCount.

El TemplatePagerField campo proporciona el PagerCommand evento , que normalmente se usa para realizar una tarea cuando se hace clic en un botón de la PagerTemplate plantilla.

Constructores

TemplatePagerField()

Inicializa una nueva instancia de la clase TemplatePagerField.

Propiedades

DataPager

Obtiene una referencia al elemento de paginación de datos al que está asociado el objeto DataPagerField.

(Heredado de DataPagerField)
IsTrackingViewState

Obtiene un valor que indica si el objeto DataPagerField está realizando un seguimiento de los cambios en su estado de vista.

(Heredado de DataPagerField)
PagerTemplate

Obtiene o establece el contenido personalizado del campo de paginación de un control DataPager.

QueryStringHandled

Obtiene o establece un valor que indica si se ha evaluado el campo de cadena de consulta.

(Heredado de DataPagerField)
QueryStringValue

Recibe el valor del campo de cadena de consulta de la dirección URL de la solicitud.

(Heredado de DataPagerField)
ViewState

Obtiene un diccionario con información de estado que permite guardar y restaurar el estado de vista de un objeto DataPagerField en distintas solicitudes de la misma página.

(Heredado de DataPagerField)
Visible

Obtiene o establece un valor que indica si debe representarse un campo de paginación de datos.

(Heredado de DataPagerField)

Métodos

CloneField()

Crea una copia del objeto actual que se deriva de DataPagerField.

(Heredado de DataPagerField)
CopyProperties(DataPagerField)

Copia las propiedades del objeto TemplatePagerField actual al objeto DataPagerField especificado.

CreateDataPagers(DataPagerFieldItem, Int32, Int32, Int32, Int32)

Crea los controles de interfaz de usuario (UI) para el objeto de campo de paginación y los agrega al contenedor especificado.

CreateField()

Crea y devuelve una nueva instancia de la clase TemplatePagerField.

Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
GetHashCode()

Sirve como la función hash predeterminada.

(Heredado de Object)
GetQueryStringNavigateUrl(Int32)

Crea una dirección URL que contiene un campo de cadena de consulta con el número de página especificado.

(Heredado de DataPagerField)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
HandleEvent(CommandEventArgs)

Controla los eventos que producen en el objeto TemplatePagerField y realiza la acción adecuada.

LoadViewState(Object)

Restaura la información estado de vista que se guardó previamente.

(Heredado de DataPagerField)
MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
OnFieldChanged()

Genera el evento FieldChanged.

(Heredado de DataPagerField)
OnPagerCommand(DataPagerCommandEventArgs)

Genera el evento PagerCommand.

SaveViewState()

Guarda los cambios realizados en el estado de vista del objeto DataPagerField.

(Heredado de DataPagerField)
ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)
TrackViewState()

Hace que el objeto DataPagerField realice un seguimiento de los cambios de su estado de vista, de modo que puedan almacenarse en la propiedad ViewState del control y mantenerse en todas las solicitudes de la misma página.

(Heredado de DataPagerField)

Eventos

PagerCommand

Se produce cuando se hace clic en un botón de un objeto TemplatePagerField.

Implementaciones de interfaz explícitas

IStateManager.IsTrackingViewState

Obtiene un valor que indica si el objeto DataPagerField está realizando un seguimiento de los cambios en su estado de vista.

(Heredado de DataPagerField)
IStateManager.LoadViewState(Object)

Restaura la información estado de vista que se guardó previamente.

(Heredado de DataPagerField)
IStateManager.SaveViewState()

Guarda los cambios realizados en el estado de vista del objeto DataPagerField.

(Heredado de DataPagerField)
IStateManager.TrackViewState()

Hace que el objeto DataPagerField realice un seguimiento de los cambios de su estado de vista, de modo que puedan almacenarse en la propiedad ViewState del control y mantenerse en todas las solicitudes de la misma página.

(Heredado de DataPagerField)

Se aplica a

Consulte también