Rappresenta un campo DataPager che consente di creare un'interfaccia di paging personalizzata.
System.Web.UI.WebControls.DataPagerField
System.Web.UI.WebControls.TemplatePagerField
Spazio dei nomi: System.Web.UI.WebControls
Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
Public Class TemplatePagerField _ Inherits DataPagerField
public class TemplatePagerField : DataPagerField
public ref class TemplatePagerField : public DataPagerField
type TemplatePagerField = class inherit DataPagerField end
Il tipo TemplatePagerField espone i seguenti membri.
| Nome | Descrizione | |
|---|---|---|
|
TemplatePagerField | Inizializza una nuova istanza della classe TemplatePagerField. |
| Nome | Descrizione | |
|---|---|---|
|
DataPager | Ottiene un riferimento al pager di dati a cui l'oggetto DataPagerField è associato. (Ereditato da DataPagerField) |
|
IsTrackingViewState | Ottiene un valore che indica se l'oggetto DataPagerField tiene traccia delle modifiche apportate al relativo stato di visualizzazione. (Ereditato da DataPagerField) |
|
PagerTemplate | Ottiene o imposta il contenuto personalizzato per il campo del pager in un controllo DataPager. |
|
QueryStringHandled | Ottiene o imposta un valore che indica se il campo della stringa di query è stato valutato. (Ereditato da DataPagerField) |
|
QueryStringValue | Ottiene il valore del campo della stringa di query dall'URL della richiesta. (Ereditato da DataPagerField) |
|
ViewState | Ottiene un dizionario di informazioni sullo stato che consente di salvare e ripristinare lo stato di visualizzazione di un oggetto DataPagerField tra più richieste per la stessa pagina. (Ereditato da DataPagerField) |
|
Visible | Ottiene o imposta un valore che indica se viene eseguito il rendering di un campo del pager di dati. (Ereditato da DataPagerField) |
| Nome | Descrizione | |
|---|---|---|
|
CloneField | Infrastruttura. Crea una copia dell'oggetto corrente derivato da DataPagerField. (Ereditato da DataPagerField) |
|
CopyProperties | Copia le proprietà dell'oggetto TemplatePagerField corrente nell'oggetto DataPagerField specificato. (Esegue l'override di DataPagerField.CopyProperties(DataPagerField)). |
|
CreateDataPagers | Crea i controlli dell'interfaccia utente per l'oggetto campo del pager e li aggiunge al contenitore specificato. (Esegue l'override di DataPagerField.CreateDataPagers(DataPagerFieldItem, Int32, Int32, Int32, Int32)). |
|
CreateField | Crea e restituisce una nuova istanza della classe TemplatePagerField. (Esegue l'override di DataPagerField.CreateField()). |
|
Equals(Object) | Determina se l'oggetto Object specificato è uguale all'oggetto Object corrente. (Ereditato da Object) |
|
Finalize | Consente a un oggetto di provare a liberare risorse ed eseguire altre operazioni di pulitura prima che l'oggetto stesso venga recuperato dalla procedura di Garbage Collection. (Ereditato da Object) |
|
GetHashCode | Funge da funzione hash per un determinato tipo. (Ereditato da Object) |
|
GetQueryStringNavigateUrl | Crea un URL che contiene un campo della stringa di query con il numero di pagina specificato. (Ereditato da DataPagerField) |
|
GetType | Ottiene l'oggetto Type dell'istanza corrente. (Ereditato da Object) |
|
HandleEvent | Gestisce gli eventi che si verificano nell'oggetto TemplatePagerField ed esegue l'azione appropriata. (Esegue l'override di DataPagerField.HandleEvent(CommandEventArgs)). |
|
LoadViewState | Ripristina informazioni sullo stato di visualizzazione salvate in precedenza. (Ereditato da DataPagerField) |
|
MemberwiseClone | Consente di creare una copia dei riferimenti dell'oggetto Object corrente. (Ereditato da Object) |
|
OnFieldChanged | Genera l'evento FieldChanged. (Ereditato da DataPagerField) |
|
OnPagerCommand | Genera l'evento PagerCommand. |
|
SaveViewState | Salva le modifiche apportate allo stato di visualizzazione dell'oggetto DataPagerField. (Ereditato da DataPagerField) |
|
ToString | Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
|
TrackViewState | Determina la registrazione da parte dell'oggetto DataPagerField delle modifiche apportate al relativo stato di visualizzazione per consentirne l'archiviazione nella proprietà ViewState del controllo e la conservazione nelle richieste relative alla stessa pagina. (Ereditato da DataPagerField) |
| Nome | Descrizione | |
|---|---|---|
|
PagerCommand | Si verifica quando viene fatto clic su un pulsante in un oggetto TemplatePagerField. |
| Nome | Descrizione | |
|---|---|---|
|
IStateManager.IsTrackingViewState | Infrastruttura. Ottiene un valore che indica se l'oggetto DataPagerField tiene traccia delle modifiche apportate al relativo stato di visualizzazione. (Ereditato da DataPagerField) |
|
IStateManager.LoadViewState | Infrastruttura. Ripristina informazioni sullo stato di visualizzazione salvate in precedenza. (Ereditato da DataPagerField) |
|
IStateManager.SaveViewState | Infrastruttura. Salva le modifiche apportate allo stato di visualizzazione dell'oggetto DataPagerField. (Ereditato da DataPagerField) |
|
IStateManager.TrackViewState | Infrastruttura. Determina la registrazione da parte dell'oggetto DataPagerField delle modifiche apportate al relativo stato di visualizzazione per consentirne l'archiviazione nella proprietà ViewState del controllo e la conservazione nelle richieste relative alla stessa pagina. (Ereditato da DataPagerField) |
Utilizzare l'oggetto TemplatePagerField per visualizzare i controlli di spostamento che consentono agli utenti di spostarsi nei dati visualizzati da un controllo che implementa l'interfaccia IPageableItemContainer. Un esempio è rappresentato dal controllo ListView. È inoltre possibile utilizzare l'oggetto TemplatePagerField per visualizzare informazioni sull'origine dati sottostante, ad esempio il numero complessivo di record e il numero di pagina corrente.
Il campo TemplatePagerField non include un layout incorporato. È pertanto necessario crearlo in modo esplicito nel modello PagerTemplate. È possibile formattare il contenuto utilizzando le classi dei fogli di stile CSS o elementi di stile in linea.
È possibile fare riferimento al controllo DataPager contenente l'oggetto TemplatePagerField utilizzando la proprietà Container. Questa operazione risulta utile quando si desidera creare espressioni di associazione per mostrare quanti record sono stati recuperati, il numero totale di pagine e altre informazioni del genere. Queste espressioni di associazione possono utilizzare le proprietà del controllo DataPager, ad esempio MaximumRows, PageSize, StartRowIndex e TotalRowCount.
Il campo TemplatePagerField fornisce l'evento PagerCommand che in genere viene utilizzato per eseguire un'attività quando viene fatto clic su un pulsante nel modello PagerTemplate.
Nell'esempio riportato di seguito viene illustrato come aggiungere un campo TemplatePagerField in un controllo DataPager. In questo esempio viene utilizzato TemplatePagerField per visualizzare il numero di pagina corrente, il numero totale di pagine e il numero totale di record. Il controllo DataPager contiene inoltre due campi NextPreviousPagerField e un campo NumericPagerField per la visualizzazione dei controlli di spostamento che consentono agli utenti di spostarsi tra i dati.
<%@ 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>
<%@ 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>
Nell'esempio riportato di seguito viene illustrato come utilizzare l'evento PagerCommand per eseguire un'azione diversa in base al pulsante su cui è stato fatto clic in un campo TemplatePagerField. In questo esempio viene utilizzato TemplatePagerField per visualizzare controlli di spostamento che consentono agli utenti di spostarsi tra i dati.
<%@ 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"> 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 </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>
<%@ 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"> 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; } } </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>
.NET Framework
Supportato in: 4, 3.5Windows 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.