DetailsView.PagerTemplate Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene o imposta il contenuto personalizzato per la riga di spostamento in un controllo DetailsView.
public:
virtual property System::Web::UI::ITemplate ^ PagerTemplate { System::Web::UI::ITemplate ^ get(); void set(System::Web::UI::ITemplate ^ value); };
[System.ComponentModel.Browsable(false)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
[System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.DetailsView))]
public virtual System.Web.UI.ITemplate PagerTemplate { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.DetailsView))>]
member this.PagerTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property PagerTemplate As ITemplate
Valore della proprietà
Un oggetto ITemplate con il contenuto personalizzato per la riga di spostamento. Il valore predefinito è Null, a indicare che questa proprietà non è impostata.
- Attributi
Esempio
Nell'esempio di codice seguente viene illustrato come utilizzare la PagerTemplate proprietà per creare una riga di cercapersone personalizzata.
<%@ 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 CustomerDetailView_DataBound(object sender, EventArgs e)
{
// Get the pager row.
DetailsViewRow pagerRow = CustomerDetailView.BottomPagerRow;
// Get the Label controls that display the current page information
// from the pager row.
Label pageNum = (Label)pagerRow.Cells[0].FindControl("PageNumberLabel");
Label totalNum = (Label)pagerRow.Cells[0].FindControl("TotalPagesLabel");
if ((pageNum != null) && (totalNum != null))
{
// Update the Label controls with the current page values.
int page = CustomerDetailView.DataItemIndex + 1;
int count = CustomerDetailView.DataItemCount;
pageNum.Text = page.ToString();
totalNum.Text = count.ToString();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DetailsView PagerTemplate Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>DetailsView PagerTemplate Example</h3>
<!-- Notice that the LinkButton controls in the pager -->
<!-- template have their CommandName properties set. -->
<!-- The DetailsView control automatically recognizes -->
<!-- certain command names and performs the appropriate -->
<!-- operation. In this example, the CommandName -->
<!-- properties are set "Page" and the CommandArgument -->
<!-- properties are set to "Next" and "Prev", which -->
<!-- causes the DetailsView control to navigate to the -->
<!-- next and previous record, respectively. -->
<asp:detailsview id="CustomerDetailView"
datasourceid="DetailsViewSource"
autogeneraterows="true"
allowpaging="true"
runat="server" OnDataBound="CustomerDetailView_DataBound">
<headerstyle backcolor="Navy"
forecolor="White"/>
<pagerstyle VerticalAlign="Bottom" />
<pagertemplate>
<table width="100%">
<tr>
<td>
<asp:LinkButton id="PreviousButton"
text="<"
CommandName="Page"
CommandArgument="Prev"
runat="Server"/>
<asp:LinkButton id="NextButton"
text=">"
CommandName="Page"
CommandArgument="Next"
runat="Server"/>
</td>
<td align="right">
Page <asp:Label id="PageNumberLabel" runat="server" />
of <asp:Label id="TotalPagesLabel" runat="server" />
</td>
</tr>
</table>
</pagertemplate>
</asp:detailsview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the web.config file. -->
<asp:SqlDataSource ID="DetailsViewSource" runat="server"
ConnectionString=
"<%$ ConnectionStrings:NorthWindConnectionString%>"
InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)"
SelectCommand="Select [CustomerID], [CompanyName],
[Address], [City], [PostalCode], [Country] From
[Customers]">
</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">
Protected Sub CustomerDetailView_DataBound(ByVal sender As Object, ByVal e As EventArgs)
' Get the pager row.
Dim pagerRow As DetailsViewRow = CustomerDetailView.BottomPagerRow
' Get the Label controls that display the current page information
' from the pager row.
Dim pageNum As Label = CType(pagerRow.Cells(0).FindControl("PageNumberLabel"), Label)
Dim totalNum As Label = CType(pagerRow.Cells(0).FindControl("TotalPagesLabel"), Label)
If (pageNum IsNot Nothing) And (totalNum IsNot Nothing) Then
' Update the Label controls with the current page values.
Dim page As Integer = CustomerDetailView.DataItemIndex + 1
Dim count As Integer = CustomerDetailView.DataItemCount
pageNum.Text = page.ToString()
totalNum.Text = count.ToString()
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DetailsView PagerTemplate Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>DetailsView PagerTemplate Example</h3>
<!-- Notice that the LinkButton controls in the pager -->
<!-- template have their CommandName properties set. -->
<!-- The DetailsView control automatically recognizes -->
<!-- certain command names and performs the appropriate -->
<!-- operation. In this example, the CommandName -->
<!-- properties are set "Page" and the CommandArgument -->
<!-- properties are set to "Next" and "Prev", which -->
<!-- causes the DetailsView control to navigate to the -->
<!-- next and previous record, respectively. -->
<asp:detailsview id="CustomerDetailView"
datasourceid="DetailsViewSource"
autogeneraterows="true"
allowpaging="true"
runat="server" OnDataBound="CustomerDetailView_DataBound">
<headerstyle backcolor="Navy"
forecolor="White"/>
<pagerstyle VerticalAlign="Bottom" />
<pagertemplate>
<table width="100%">
<tr>
<td>
<asp:LinkButton id="PreviousButton"
text="<"
CommandName="Page"
CommandArgument="Prev"
runat="Server"/>
<asp:LinkButton id="NextButton"
text=">"
CommandName="Page"
CommandArgument="Next"
runat="Server"/>
</td>
<td align="right">
Page <asp:Label id="PageNumberLabel" runat="server" />
of <asp:Label id="TotalPagesLabel" runat="server" />
</td>
</tr>
</table>
</pagertemplate>
</asp:detailsview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the web.config file. -->
<asp:SqlDataSource ID="DetailsViewSource" runat="server"
ConnectionString=
"<%$ ConnectionStrings:NorthWindConnectionString%>"
InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)"
SelectCommand="Select [CustomerID], [CompanyName],
[Address], [City], [PostalCode], [Country] From
[Customers]">
</asp:SqlDataSource>
</form>
</body>
</html>
Commenti
Una riga del cercapersone viene visualizzata in un DetailsView controllo quando la funzionalità di paging è abilitata (impostando la AllowPaging proprietà su true). La riga del cercapersone contiene i controlli che consentono all'utente di passare alle diverse pagine del controllo. Anziché usare l'interfaccia utente della riga del cercapersone predefinita, è possibile definire un'interfaccia utente personalizzata usando la PagerTemplate proprietà . Per specificare un modello personalizzato per la riga del cercapersone, posizionare <PagerTemplate>
prima i tag tra i tag di apertura e chiusura del DetailsView controllo. È quindi possibile elencare il contenuto del modello tra i tag di apertura e chiusura <PagerTemplate>
. Per controllare l'aspetto della riga del cercapersone, utilizzare la PagerStyle proprietà .