TemplatePagerField Classe

Definição

Representa um campo DataPager que permite criar uma interface do usuário de paginação 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
Herança
TemplatePagerField

Exemplos

O exemplo a seguir mostra como adicionar um TemplatePagerField campo em um DataPager controle . Este exemplo usa o TemplatePagerField para exibir o número de página atual, o número total de páginas e o número total de registros. O DataPager controle também contém dois NextPreviousPagerField campos e um NumericPagerField campo para exibir controles de navegação que permitem que os usuários paginem por meio de dados.

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

O exemplo a seguir mostra como usar o PagerCommand evento para executar uma ação diferente dependendo de qual botão foi clicado em um TemplatePagerField campo. Este exemplo usa o para exibir controles TemplatePagerField de navegação que permitem que os usuários usem a página por meio de dados.

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

Comentários

Use o TemplatePagerField objeto para exibir controles de navegação que permitem que os usuários usem a página por meio de dados exibidos por um controle que implementa a IPageableItemContainer interface. (Um exemplo é o ListView controle.) Você também pode usar o TemplatePagerField objeto para exibir informações sobre a fonte de dados subjacente, como o número total de registros e o número da página atual.

O TemplatePagerField campo não tem nenhum layout interno. Portanto, você deve criar explicitamente o layout no PagerTemplate modelo. Você pode formatar o conteúdo usando classes CSS (folhas de estilo em cascata) ou elementos de estilo embutidos.

Você pode referenciar o DataPager controle que contém o TemplatePagerField objeto usando a Container propriedade . Isso é útil quando você deseja criar expressões de associação para mostrar quantos registros foram recuperados, o número total de páginas e informações semelhantes. Essas expressões de associação podem usar propriedades do DataPager controle, como MaximumRows, PageSize, StartRowIndexe TotalRowCount.

O TemplatePagerField campo fornece o PagerCommand evento , que normalmente é usado para executar uma tarefa quando um botão no PagerTemplate modelo é clicado.

Construtores

TemplatePagerField()

Inicializa uma nova instância da classe TemplatePagerField.

Propriedades

DataPager

Obtém uma referência à paginação de dados ao qual o objeto DataPagerField está associado.

(Herdado de DataPagerField)
IsTrackingViewState

Obtém um valor que indica se o objeto DataPagerField está controlando suas alterações de estado de exibição.

(Herdado de DataPagerField)
PagerTemplate

Obtém ou define o conteúdo personalizado para o campo de paginação em um controle DataPager.

QueryStringHandled

Obtém ou define um valor que indica se o campo da cadeia de consulta foi avaliado.

(Herdado de DataPagerField)
QueryStringValue

Obtém o valor do campo de cadeia de consulta da URL da solicitação.

(Herdado de DataPagerField)
ViewState

Obtém um dicionário de informações de estado que permite salvar e restaurar o estado de exibição de um objeto DataPagerField em várias solicitações para a mesma página.

(Herdado de DataPagerField)
Visible

Obtém ou define um valor que indica se um campo de paginação de dados é renderizado.

(Herdado de DataPagerField)

Métodos

CloneField()

Cria uma cópia do objeto atual derivada de DataPagerField.

(Herdado de DataPagerField)
CopyProperties(DataPagerField)

Copia as propriedades do objeto TemplatePagerField atual para o objeto DataPagerField especificado.

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

Cria os controles da interface do usuário para o objeto de campo do pager e os adiciona ao contêiner especificado.

CreateField()

Cria e retorna uma nova instância da classe TemplatePagerField.

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetHashCode()

Serve como a função de hash padrão.

(Herdado de Object)
GetQueryStringNavigateUrl(Int32)

Cria uma URL que contém um campo de cadeia de consulta que tem o número de página especificado.

(Herdado de DataPagerField)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
HandleEvent(CommandEventArgs)

Manipula os eventos que ocorrem no objeto TemplatePagerField e executa a ação apropriada.

LoadViewState(Object)

Restaura as informações de estado de exibição salvas anteriormente.

(Herdado de DataPagerField)
MemberwiseClone()

Cria uma cópia superficial do Object atual.

(Herdado de Object)
OnFieldChanged()

Aciona o evento FieldChanged.

(Herdado de DataPagerField)
OnPagerCommand(DataPagerCommandEventArgs)

Aciona o evento PagerCommand.

SaveViewState()

Salva as alterações feitas ao estado de exibição do objeto DataPagerField.

(Herdado de DataPagerField)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)
TrackViewState()

Faz com que o objeto DataPagerField controle as alterações em seu estado de exibição, de modo que elas possam ser armazenadas na propriedade ViewState do controle e persistidas entre solicitações para a mesma página.

(Herdado de DataPagerField)

Eventos

PagerCommand

Ocorre quando se clica em um botão em um objeto TemplatePagerField.

Implantações explícitas de interface

IStateManager.IsTrackingViewState

Obtém um valor que indica se o objeto DataPagerField está controlando suas alterações de estado de exibição.

(Herdado de DataPagerField)
IStateManager.LoadViewState(Object)

Restaura as informações de estado de exibição salvas anteriormente.

(Herdado de DataPagerField)
IStateManager.SaveViewState()

Salva as alterações feitas ao estado de exibição do objeto DataPagerField.

(Herdado de DataPagerField)
IStateManager.TrackViewState()

Faz com que o objeto DataPagerField controle as alterações em seu estado de exibição, de modo que elas possam ser armazenadas na propriedade ViewState do controle e persistidas entre solicitações para a mesma página.

(Herdado de DataPagerField)

Aplica-se a

Confira também