Proprietà ListView.LayoutTemplate (System.Web.UI.WebControls)

Cambia visualizzazione:
ScriptFree
Riferimento a .NET Framework
Proprietà ListView.LayoutTemplate
Il presente articolo è stato tradotto manualmente. Per visualizzare questa pagina e contemporaneamente visualizzarne il contenuto in lingua inglese, passare alla visualizzazione semplificata.

Ottiene o imposta il contenuto personalizzato per il contenitore radice in un controllo ListView.

Spazio dei nomi:  System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)
Sintassi

Visual Basic
<BrowsableAttribute(False)> _
<PersistenceModeAttribute(PersistenceMode.InnerProperty)> _
<TemplateContainerAttribute(GetType(ListView))> _
Public Overridable Property LayoutTemplate As ITemplate
	Get
	Set
C#
[BrowsableAttribute(false)]
[PersistenceModeAttribute(PersistenceMode.InnerProperty)]
[TemplateContainerAttribute(typeof(ListView))]
public virtual ITemplate LayoutTemplate { get; set; }
Visual C++
[BrowsableAttribute(false)]
[PersistenceModeAttribute(PersistenceMode::InnerProperty)]
[TemplateContainerAttribute(typeof(ListView))]
public:
virtual property ITemplate^ LayoutTemplate {
	ITemplate^ get ();
	void set (ITemplate^ value);
}
F#
[<BrowsableAttribute(false)>]
[<PersistenceModeAttribute(PersistenceMode.InnerProperty)>]
[<TemplateContainerAttribute(typeof(ListView))>]
abstract LayoutTemplate : ITemplate with get, set
[<BrowsableAttribute(false)>]
[<PersistenceModeAttribute(PersistenceMode.InnerProperty)>]
[<TemplateContainerAttribute(typeof(ListView))>]
override LayoutTemplate : ITemplate with get, set
ASP.NET
<asp:ListView>
	<LayoutTemplate>ITemplate</LayoutTemplate>
</asp:ListView>

Valore proprietà

Tipo: System.Web.UI.ITemplate
Oggetto che include il contenuto personalizzato del contenitore radice in un controllo ListView. Il valore predefinito è null, a indicare che questa proprietà non è impostata.
Note

Utilizzare la proprietà LayoutTemplate per definire un'interfaccia utente personalizzata per il contenitore radice del controllo ListView.

Per specificare il modello del layout, aggiungere un elemento LayoutTemplate all'interno del controllo ListView. Sarà quindi possibile aggiungere il contenuto del modello all'elemento LayoutTemplate.

Il contenuto LayoutTemplate deve includere un controllo segnaposto, ad esempio un elemento riga di una tabella (tr) per gli elementi definiti dal modello ItemTemplate o per i gruppi definiti dal modello GroupTemplate. Il controllo segnaposto deve avere l'attributo runat impostato su "server" e l'attributo ID impostato sul valore della proprietà ItemPlaceholderID o GroupPlaceholderID, se il controllo ListView utilizza i gruppi.

Il modello LayoutTemplate non è richiesto dal controllo ListView. È possibile utilizzare il controllo ListView senza un LayoutTemplate e anche senza un controllo server del segnaposto con un ID noto.

Esempi

Nell'esempio riportato di seguito viene illustrato come definire un modello personalizzato per il contenitore radice in un controllo ListView.

Nota sulla sicurezza Nota sulla sicurezza

L'esempio include una casella di testo che accetta l'input dell'utente e rappresenta quindi una potenziale minaccia alla sicurezza. Per impostazione predefinita, le pagine Web ASP.NET verificano che l'input dell'utente non includa script o elementi HTML. Per ulteriori informazioni, vedere Cenni preliminari sugli attacchi tramite script.

Visual Basic

<%@ 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>ListView Templates Example</title>
  </head>
  <body>
    <form id="form1" runat="server">

      <h3>ListView Templates Example</h3>

      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource" 
        DataKeyNames="ContactID"
        runat="server">
        <LayoutTemplate>
          <table cellpadding="2" width="640px" border="1" runat="server" id="tblProducts">
            <tr runat="server">
              <th runat="server">Action</th>
              <th runat="server">First Name</th>
              <th runat="server">Last Name</th>
            </tr>
            <tr runat="server" id="itemPlaceholder" />
          </table>
          <asp:DataPager runat="server" ID="ContactsDataPager" PageSize="12">
            <Fields>
              <asp:NextPreviousPagerField ShowFirstPageButton="True" ShowLastPageButton="True"
                FirstPageText="|&lt;&lt; " LastPageText=" &gt;&gt;|"
                NextPageText=" &gt; " PreviousPageText=" &lt; " />
            </Fields>
          </asp:DataPager>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td>
              <asp:LinkButton ID="EditButton" runat="Server" Text="Edit" CommandName="Edit" />
            </td>
            <td>
              <asp:Label ID="FirstNameLabel" runat="Server" Text='<%#Eval("FirstName") %>' />
            </td>
            <td valign="top">
              <asp:Label ID="LastNameLabel" runat="Server" Text='<%#Eval("LastName") %>' />
            </td>
          </tr>
        </ItemTemplate>
        <EditItemTemplate>
          <tr style="background-color: #ADD8E6">
            <td>
              <asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />&nbsp;
              <asp:LinkButton ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
            </td>
            <td>
              <asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>' 
                MaxLength="50" /><br />
            </td>
            <td>
              <asp:TextBox ID="LastNameTextBox" runat="server" Text='<%# Bind("LastName") %>' 
                MaxLength="50" /><br />
            </td>
          </tr>
        </EditItemTemplate>
      </asp:ListView>

      <!-- 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"
        UpdateCommand="UPDATE Person.Contact
                       SET FirstName = @FirstName, LastName = @LastName
                       WHERE ContactID = @ContactID">
      </asp:SqlDataSource>

    </form>
  </body>
</html>


C#

<%@ 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>ListView Templates Example</title>
  </head>
  <body>
    <form id="form1" runat="server">

      <h3>ListView Templates Example</h3>

      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource" 
        DataKeyNames="ContactID"
        runat="server">
        <LayoutTemplate>
          <table cellpadding="2" width="640px" border="1" runat="server" id="tblProducts">
            <tr runat="server">
              <th runat="server">Action</th>
              <th runat="server">First Name</th>
              <th runat="server">Last Name</th>
            </tr>
            <tr runat="server" id="itemPlaceholder" />
          </table>
          <asp:DataPager runat="server" ID="ContactsDataPager" PageSize="12">
            <Fields>
              <asp:NextPreviousPagerField ShowFirstPageButton="true" ShowLastPageButton="true"
                FirstPageText="|&lt;&lt; " LastPageText=" &gt;&gt;|"
                NextPageText=" &gt; " PreviousPageText=" &lt; " />
            </Fields>
          </asp:DataPager>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td>
              <asp:LinkButton ID="EditButton" runat="Server" Text="Edit" CommandName="Edit" />
            </td>
            <td>
              <asp:Label ID="FirstNameLabel" runat="Server" Text='<%#Eval("FirstName") %>' />
            </td>
            <td valign="top">
              <asp:Label ID="LastNameLabel" runat="Server" Text='<%#Eval("LastName") %>' />
            </td>
          </tr>
        </ItemTemplate>
        <EditItemTemplate>
          <tr style="background-color: #ADD8E6">
            <td>
              <asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />&nbsp;
              <asp:LinkButton ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
            </td>
            <td>
              <asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%#Bind("FirstName") %>' 
                MaxLength="50" /><br />
            </td>
            <td>
              <asp:TextBox ID="LastNameTextBox" runat="server" Text='<%#Bind("LastName") %>' 
                MaxLength="50" /><br />
            </td>
          </tr>
        </EditItemTemplate>
      </asp:ListView>

      <!-- 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"
        UpdateCommand="UPDATE Person.Contact
                       SET FirstName = @FirstName, LastName = @LastName
                       WHERE ContactID = @ContactID">
      </asp:SqlDataSource>

    </form>
  </body>
</html>


Nell'esempio riportato di seguito viene illustrato come utilizzare il controllo ListView senza definire un modello LayoutTemplate nel controllo. Inoltre un controllo server con un ID noto non è specificato.

<asp:ListView ID="ListView1" runat="server">
  <ItemTemplate>
    <% Eval("LastName")%>
  </ItemTemplate>
</asp:ListView>
Informazioni sulla versione

.NET Framework

Supportato in: 4, 3.5
Piattaforme

Windows 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.
Vedere anche

Riferimenti

Altre risorse