TemplatePagerField Klasa

Definicja

DataPager Reprezentuje pole, które umożliwia utworzenie niestandardowego interfejsu użytkownika stronicowania.

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
Dziedziczenie
TemplatePagerField

Przykłady

W poniższym przykładzie pokazano, jak dodać TemplatePagerField pole w kontrolce DataPager . W tym przykładzie użyto elementu TemplatePagerField , aby wyświetlić bieżącą liczbę stron, łączną liczbę stron i łączną liczbę rekordów. Kontrolka DataPager zawiera również dwa NextPreviousPagerField pola i NumericPagerField pole do wyświetlania kontrolek nawigacji, które umożliwiają użytkownikom stronicowanie danych.

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

W poniższym przykładzie pokazano, jak za pomocą PagerCommand zdarzenia wykonać inną akcję w zależności od tego, który przycisk został kliknięty w TemplatePagerField polu. W tym przykładzie użyto kontrolki TemplatePagerField nawigacji umożliwiającej użytkownikom stronicowanie danych.

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

Uwagi

Użyj obiektu, TemplatePagerField aby wyświetlić kontrolki nawigacji, które umożliwiają użytkownikom stronicowanie danych wyświetlanych przez kontrolkę IPageableItemContainer , która implementuje interfejs. (Przykładem jest kontrolka ListView ). Obiekt służy również TemplatePagerField do wyświetlania informacji o bazowym źródle danych, takich jak całkowita liczba rekordów i numer bieżącej strony.

Pole TemplatePagerField nie ma wbudowanego układu. W związku z tym należy jawnie utworzyć układ w szablonie PagerTemplate . Zawartość można sformatować przy użyciu kaskadowych klas stylów (CSS) lub wbudowanych elementów stylu.

Kontrolkę DataPager zawierającą TemplatePagerField obiekt można odwołać przy użyciu Container właściwości . Jest to przydatne, gdy chcesz utworzyć wyrażenia powiązania, aby pokazać, ile rekordów zostało pobranych, łączną liczbę stron i podobnych informacji. Te wyrażenia powiązań mogą używać właściwości kontrolki DataPager , takich jak MaximumRows, PageSize, StartRowIndexi TotalRowCount.

Pole TemplatePagerField zawiera PagerCommand zdarzenie, które jest zwykle używane do wykonywania zadania po kliknięciu przycisku w szablonie PagerTemplate .

Konstruktory

TemplatePagerField()

Inicjuje nowe wystąpienie klasy TemplatePagerField.

Właściwości

DataPager

Pobiera odwołanie do stronicowania danych skojarzonego DataPagerField z obiektem.

(Odziedziczone po DataPagerField)
IsTrackingViewState

Pobiera wartość wskazującą, czy DataPagerField obiekt śledzi zmiany stanu widoku.

(Odziedziczone po DataPagerField)
PagerTemplate

Pobiera lub ustawia niestandardową zawartość pola pager w kontrolce DataPager .

QueryStringHandled

Pobiera lub ustawia wartość wskazującą, czy pole ciągu zapytania zostało ocenione.

(Odziedziczone po DataPagerField)
QueryStringValue

Pobiera wartość pola ciągu zapytania z adresu URL żądania.

(Odziedziczone po DataPagerField)
ViewState

Pobiera słownik informacji o stanie, który umożliwia zapisywanie i przywracanie stanu DataPagerField widoku obiektu w wielu żądaniach dla tej samej strony.

(Odziedziczone po DataPagerField)
Visible

Pobiera lub ustawia wartość wskazującą, czy pole stronicowania danych jest renderowane.

(Odziedziczone po DataPagerField)

Metody

CloneField()

Tworzy kopię bieżącego obiektu, który pochodzi z DataPagerFieldklasy .

(Odziedziczone po DataPagerField)
CopyProperties(DataPagerField)

Kopiuje właściwości bieżącego TemplatePagerField obiektu do określonego DataPagerField obiektu.

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

Tworzy kontrolki interfejsu użytkownika dla obiektu pola pager i dodaje je do określonego kontenera.

CreateField()

Tworzy i zwraca nowe wystąpienie TemplatePagerField klasy.

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetQueryStringNavigateUrl(Int32)

Tworzy adres URL zawierający pole ciągu zapytania, które ma określony numer strony.

(Odziedziczone po DataPagerField)
GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
HandleEvent(CommandEventArgs)

Obsługuje zdarzenia występujące w TemplatePagerField obiekcie i wykonuje odpowiednią akcję.

LoadViewState(Object)

Przywraca informacje o stanie widoku, które zostały zapisane wcześniej.

(Odziedziczone po DataPagerField)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
OnFieldChanged()

FieldChanged Zgłasza zdarzenie.

(Odziedziczone po DataPagerField)
OnPagerCommand(DataPagerCommandEventArgs)

PagerCommand Zgłasza zdarzenie.

SaveViewState()

Zapisuje zmiany wprowadzone w DataPagerField stanie widoku obiektu.

(Odziedziczone po DataPagerField)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)
TrackViewState()

DataPagerField Powoduje, że obiekt śledzi zmiany w stanie widoku, aby można je było przechowywać we właściwości kontrolki ViewState i utrwalać na żądaniach dla tej samej strony.

(Odziedziczone po DataPagerField)

Zdarzenia

PagerCommand

Występuje po kliknięciu TemplatePagerField przycisku w obiekcie.

Jawne implementacje interfejsu

IStateManager.IsTrackingViewState

Pobiera wartość wskazującą, czy DataPagerField obiekt śledzi zmiany stanu widoku.

(Odziedziczone po DataPagerField)
IStateManager.LoadViewState(Object)

Przywraca informacje o stanie widoku, które zostały zapisane wcześniej.

(Odziedziczone po DataPagerField)
IStateManager.SaveViewState()

Zapisuje zmiany wprowadzone w DataPagerField stanie widoku obiektu.

(Odziedziczone po DataPagerField)
IStateManager.TrackViewState()

DataPagerField Powoduje, że obiekt śledzi zmiany w stanie widoku, aby można je było przechowywać we właściwości kontrolki ViewState i utrwalać na żądaniach dla tej samej strony.

(Odziedziczone po DataPagerField)

Dotyczy

Zobacz też