WebPartZoneCollection Classe

Definizione

Contiene un insieme in sola lettura di controlli WebPartZone.Contains a read-only collection of WebPartZone controls.

public ref class WebPartZoneCollection sealed : System::Collections::ReadOnlyCollectionBase
public sealed class WebPartZoneCollection : System.Collections.ReadOnlyCollectionBase
type WebPartZoneCollection = class
    inherit ReadOnlyCollectionBase
Public NotInheritable Class WebPartZoneCollection
Inherits ReadOnlyCollectionBase
Ereditarietà
WebPartZoneCollection

Esempi

Nell'esempio di codice riportato di seguito viene illustrato WebPartZoneCollection l'utilizzo della classe.The following code example demonstrates the use of the WebPartZoneCollection class. L'esempio di codice contiene tre parti: due sezioni di codice e una spiegazione su come eseguire l'esempio.The code example contains three parts: two sections of code, and an explanation of how to run the example.

La prima parte dell'esempio di codice è una pagina Web che contiene tre WebPartZone controlli, ognuno dei quali contiene un singolo controllo server.The first part of the code example is a Web page that contains three WebPartZone controls, each of which contains a single server control. Sebbene questi controlli server siano tutti controlli ASP.NET standard, possono fungere da WebPart controlli in fase di esecuzione perché sono posizionati all' WebPartZone interno di una zona.Although these server controls are all standard ASP.NET controls, they can act as WebPart controls at run time because they are placed within a WebPartZone zone.

<%@ Page Language="C#" 
    Codefile="webpartzonecollection_overview.cs" 
    Inherits="webpartzonecollection_overview" %>

<!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>WebPartZoneCollection Demo</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:WebPartManager ID="mgr" runat="server" />
    <asp:Table ID="Table1" runat="server">
      <asp:TableRow>
        <asp:TableCell>
          <asp:Label ID="lblZone1" runat="server" 
            Font-Bold="true"
            AssociatedControlID="WebPartZone1">
            WebPartZone1 Contents
          </asp:Label>
          <asp:WebPartZone ID="WebPartZone1" 
            runat="server" Width="230">
            <ZoneTemplate>
              <asp:BulletedList 
                ID="BulletedList1" 
                Runat="server"
                DisplayMode="HyperLink"
                Title="Favorite Links">
                <asp:ListItem 
                  Value="http://msdn.microsoft.com">
                  MSDN
                </asp:ListItem>
                <asp:ListItem Value="http://www.asp.net">
                  ASP.NET
                </asp:ListItem>
                <asp:ListItem Value="http://www.msn.com">
                  MSN
                </asp:ListItem>
              </asp:BulletedList>      
            </ZoneTemplate>
          </asp:WebPartZone>
          <div>
          <asp:Label ID="lblZone2" runat="server" 
            Font-Bold="true"
            AssociatedControlID="WebPartZone2">
            WebPartZone2 Contents
          </asp:Label>
          </div>
          <asp:WebPartZone ID="WebPartZone2" 
            runat="server" Width="230">
            <ZoneTemplate>
              <asp:Calendar ID="Calendar1" 
                runat="server" 
                Title="My Calendar" 
                CatalogIconImageUrl="Mine.gif" />
            </ZoneTemplate>
          </asp:WebPartZone> 
        </asp:TableCell>
        <asp:TableCell VerticalAlign="top"> 
          <asp:Label ID="lblZone3" runat="server" 
            Font-Bold="true" 
            AssociatedControlID="WebPartZone3">
            WebPartZone3 Contents
          </asp:Label>
          <asp:WebPartZone ID="WebPartZone3" runat="server">
            <ZoneTemplate>
              <asp:Table runat="server" ID="table2" 
                Title="Employee Extensions">
                <asp:TableHeaderRow>
                  <asp:TableHeaderCell Scope="Column">
                    Employee Name</asp:TableHeaderCell>
                  <asp:TableHeaderCell Scope="Column">
                    Extension</asp:TableHeaderCell>
                </asp:TableHeaderRow>
                <asp:TableRow>
                  <asp:TableCell>Alberts, Amy</asp:TableCell>
                  <asp:TableCell>x9764</asp:TableCell>
                </asp:TableRow>                
                <asp:TableRow>
                  <asp:TableCell>Hanif, Karim</asp:TableCell>
                  <asp:TableCell>x3240</asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                  <asp:TableCell>Penor, Lori</asp:TableCell>
                  <asp:TableCell>x4165</asp:TableCell>
                </asp:TableRow>
              </asp:Table>
            </ZoneTemplate>
          </asp:WebPartZone>
        </asp:TableCell>
      </asp:TableRow>
    </asp:Table>
    </div>
    <hr />
    <asp:Table ID="Table3" runat="server">
      <asp:TableRow>
        <asp:TableCell>
          <asp:Button ID="Button1" runat="server" 
            Width ="200" OnClick="Button1_Click" 
            Text="Total Zone Count" />
          <br />
          <asp:Button ID="Button2" runat="server" 
            Width ="200" OnClick="Button2_Click"
            Text="Coll. Contains WebPartZone2" />
          <br />
          <asp:Button ID="Button3" runat="server" 
            Width ="200" OnClick="Button3_Click"
            Text="Zone Names from Array" />
          <br />
          <asp:Button ID="Button4" runat="server" 
            Width ="200" OnClick="Button4_Click"
            Text="WebPartZone1 Index" />  
          <br />
          <asp:Button ID="Button5" runat="server" 
            Width ="200" OnClick="Button5_Click"
            Text="Toggle Verb Render Mode" />
        </asp:TableCell>
        <asp:TableCell HorizontalAlign="right" 
          Width="200" VerticalAlign="top">
          <asp:Label ID="Label1" runat="server" 
            Font-Bold="true" />
        </asp:TableCell>  
      </asp:TableRow>
    </asp:Table>
    </form>
</body>
</html>
<%@ Page Language="VB" 
    Codefile="webpartzonecollection_overview.vb" 
    Inherits="webpartzonecollection_overview" %>

<!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>WebPartZoneCollection Demo</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:WebPartManager ID="mgr" runat="server" />
    <asp:Table ID="Table1" runat="server">
      <asp:TableRow>
        <asp:TableCell>
          <asp:Label ID="lblZone1" runat="server" 
            Font-Bold="true"
            AssociatedControlID="WebPartZone1">
            WebPartZone1 Contents
          </asp:Label>
          <asp:WebPartZone ID="WebPartZone1" 
            runat="server" Width="230">
            <ZoneTemplate>
              <asp:BulletedList 
                ID="BulletedList1" 
                Runat="server"
                DisplayMode="HyperLink"
                Title="Favorite Links">
                <asp:ListItem 
                  Value="http://msdn.microsoft.com">
                  MSDN
                </asp:ListItem>
                <asp:ListItem Value="http://www.asp.net">
                  ASP.NET
                </asp:ListItem>
                <asp:ListItem Value="http://www.msn.com">
                  MSN
                </asp:ListItem>
              </asp:BulletedList>      
            </ZoneTemplate>
          </asp:WebPartZone>
          <div>
          <asp:Label ID="lblZone2" runat="server" 
            Font-Bold="true"
            AssociatedControlID="WebPartZone2">
            WebPartZone2 Contents
          </asp:Label>
          </div>
          <asp:WebPartZone ID="WebPartZone2" 
            runat="server" Width="230">
            <ZoneTemplate>
              <asp:Calendar ID="Calendar1" 
                runat="server" 
                Title="My Calendar" 
                CatalogIconImageUrl="Mine.gif" />
            </ZoneTemplate>
          </asp:WebPartZone> 
        </asp:TableCell>
        <asp:TableCell VerticalAlign="top"> 
          <asp:Label ID="lblZone3" runat="server" 
            Font-Bold="true" 
            AssociatedControlID="WebPartZone3">
            WebPartZone3 Contents
          </asp:Label>
          <asp:WebPartZone ID="WebPartZone3" runat="server">
            <ZoneTemplate>
              <asp:Table runat="server" ID="table2" 
                Title="Employee Extensions">
                <asp:TableHeaderRow>
                  <asp:TableHeaderCell Scope="Column">
                    Employee Name</asp:TableHeaderCell>
                  <asp:TableHeaderCell Scope="Column">
                    Extension</asp:TableHeaderCell>
                </asp:TableHeaderRow>
                <asp:TableRow>
                  <asp:TableCell>Alberts, Amy</asp:TableCell>
                  <asp:TableCell>x9764</asp:TableCell>
                </asp:TableRow>                
                <asp:TableRow>
                  <asp:TableCell>Hanif, Karim</asp:TableCell>
                  <asp:TableCell>x3240</asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                  <asp:TableCell>Penor, Lori</asp:TableCell>
                  <asp:TableCell>x4165</asp:TableCell>
                </asp:TableRow>
              </asp:Table>
            </ZoneTemplate>
          </asp:WebPartZone>
        </asp:TableCell>
      </asp:TableRow>
    </asp:Table>
    </div>
    <hr />
    <asp:Table ID="Table3" runat="server">
      <asp:TableRow>
        <asp:TableCell>
          <asp:Button ID="Button1" runat="server" 
            Width ="200" OnClick="Button1_Click" 
            Text="Total Zone Count" />
          <br />
          <asp:Button ID="Button2" runat="server" 
            Width ="200" OnClick="Button2_Click"
            Text="Coll. Contains WebPartZone2" />
          <br />
          <asp:Button ID="Button3" runat="server" 
            Width ="200" OnClick="Button3_Click"
            Text="Zone Names from Array" />
          <br />
          <asp:Button ID="Button4" runat="server" 
            Width ="200" OnClick="Button4_Click"
            Text="WebPartZone1 Index" />  
          <br />
          <asp:Button ID="Button5" runat="server" 
            Width ="200" OnClick="Button5_Click"
            Text="Toggle Verb Render Mode" />
        </asp:TableCell>
        <asp:TableCell HorizontalAlign="right" 
          Width="200" VerticalAlign="top">
          <asp:Label ID="Label1" runat="server" 
            Font-Bold="true" />
        </asp:TableCell>  
      </asp:TableRow>
    </asp:Table>
    </form>
</body>
</html>

La seconda parte dell'esempio di codice è la classe parziale che contiene il codice per illustrare l'utilizzo WebPartZoneCollection della classe.The second part of the code example is the partial class that contains the code to demonstrate usage of the WebPartZoneCollection class. Questo codice gestisce gli eventi per la pagina Web.This code handles the events for the Web page.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class webpartzonecollection_overview : System.Web.UI.Page
{

  protected void Button1_Click(object sender, EventArgs e)
  {
    Label1.Text = String.Empty;
    Label1.Text = "WebPartZone Count:  " + mgr.Zones.Count;
  }

  protected void Button2_Click(object sender, EventArgs e)
  {
    Label1.Text = String.Empty;
    Label1.Text = mgr.Zones.Contains(WebPartZone2).ToString();
  }

  protected void Button3_Click(object sender, EventArgs e)
  {
    Label1.Text = String.Empty;
    WebPartZoneBase[] zoneArray = new WebPartZoneBase[mgr.Zones.Count];
    mgr.Zones.CopyTo(zoneArray, 0);
    Label1.Text = zoneArray[2].ID;
    Label1.Text += ", " + zoneArray[1].ID;
    Label1.Text += ", " + zoneArray[0].ID;
  }

  protected void Button4_Click(object sender, EventArgs e)
  {
    Label1.Text = String.Empty;
    Label1.Text = "WebPartZone1 index:  " + mgr.Zones.IndexOf(WebPartZone1);
  }

  protected void Button5_Click(object sender, EventArgs e)
  {
    Label1.Text = String.Empty;

    WebPartZoneCollection zoneCollection = mgr.Zones;
    foreach (WebPartZone zone in zoneCollection)
    {

      if (zone.WebPartVerbRenderMode == WebPartVerbRenderMode.Menu)
        zone.WebPartVerbRenderMode = WebPartVerbRenderMode.TitleBar;
      else
        zone.WebPartVerbRenderMode = WebPartVerbRenderMode.Menu;
    }
  }
}
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls


Partial Public Class webpartzonecollection_overview

  Inherits Page

  Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    Label1.Text = String.Empty
    Label1.Text = "WebPartZone Count:  " & mgr.Zones.Count

  End Sub


  Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs)
    Label1.Text = String.Empty
    Label1.Text = mgr.Zones.Contains(WebPartZone2).ToString()

  End Sub

  Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs)
    Label1.Text = String.Empty
    Dim zoneArray(mgr.Zones.Count) As WebPartZoneBase
    mgr.Zones.CopyTo(zoneArray, 0)
    Label1.Text = zoneArray(2).ID
    Label1.Text += ", " & zoneArray(1).ID
    Label1.Text += ", " & zoneArray(0).ID

  End Sub

  Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs)
    Label1.Text = String.Empty
    Label1.Text = "WebPartZone1 index:  " & mgr.Zones.IndexOf(WebPartZone1)

  End Sub

  Protected Sub Button5_Click(ByVal sender As Object, ByVal e As EventArgs)
    Label1.Text = String.Empty

    Dim zoneCollection As WebPartZoneCollection = mgr.Zones
    Dim zone As WebPartZone
    For Each zone In zoneCollection
      If zone.WebPartVerbRenderMode = WebPartVerbRenderMode.Menu Then
        zone.WebPartVerbRenderMode = WebPartVerbRenderMode.TitleBar
      Else
        zone.WebPartVerbRenderMode = WebPartVerbRenderMode.Menu
      End If
    Next zone

  End Sub

End Class

Caricare la pagina in un browser.Load the page in a browser. Le tre WebPartZone zone sono visibili con i relativi controlli server contenuti.The three WebPartZone zones are visible with their contained server controls. Nella parte inferiore della pagina sono presenti diversi pulsanti, ciascuno dei quali illustra un aspetto dell'utilizzo dell' WebPartZoneCollection oggetto.Near the bottom of the page are several buttons, each of which demonstrates some aspect of working with the WebPartZoneCollection object. Fare clic su ogni pulsante per verificarne l'effetto sulle zone e il relativo contenuto.Click each button to see its effect on the zones and their contents. Per visualizzare il codice associato a ciascun pulsante che illustra alcuni aspetti dell' WebPartZoneCollection oggetto, visualizzare il codice nel file di classe parziale a cui si fa riferimento sopra come seconda parte di questo esempio di codice.To view the code associated with each button that demonstrates some aspect of the WebPartZoneCollection object, view the code in the partial class file referenced above as the second part of this code example.

Commenti

La WebPartZoneCollection classe contiene la raccolta di WebPartZone controlli presenti in una pagina Web part.The WebPartZoneCollection class contains the collection of WebPartZone controls that exist on a Web Parts page. Viene usato principalmente dal WebPartManager controllo per tenere traccia e gestire tutte le zone.It is used primarily by the WebPartManager control to track and manage all the zones. Il WebPartManager controllo mantiene un riferimento alla raccolta di zone in una pagina della relativa Zones proprietà di sola lettura.The WebPartManager control keeps a reference to the collection of zones on a page in its read-only Zones property.

La WebPartZoneCollection classe è utile quando si desidera eseguire operazioni su più zone o sul relativo contenuto contemporaneamente oppure quando è necessario individuare una determinata zona ed esaminarne o modificarne il contenuto.The WebPartZoneCollection class is useful when you want to carry out operations on multiple zones or their contents at the same time, or when you need to locate a particular zone and examine or change its contents. Anche se la raccolta di zone è di sola lettura e non è possibile modificare le dimensioni dell'oggetto della raccolta, è comunque possibile ottenere riferimenti alle singole zone all'interno della raccolta e, quando si dispone di un riferimento a un singolo oggetto zona, è possibile modificare valori delle proprietà.Although the collection of zones itself is read-only and you cannot change the size of the collection object itself, you can still get references to the individual zones within the collection, and when you have a reference to an individual zone object, you can change its property values.

La WebPartZoneCollection classe dispone di due costruttori.The WebPartZoneCollection class has two constructors. Il primo, WebPartZoneCollection(), inizializza semplicemente un'istanza vuota di un nuovo WebPartZoneCollectionoggetto.The first one, WebPartZoneCollection(), simply initializes an empty instance of a new WebPartZoneCollection. Il secondo, WebPartZoneCollection(ICollection), Inizializza una raccolta passando una raccolta esistente di zone.The second one, WebPartZoneCollection(ICollection), initializes a collection by passing in an existing collection of zones.

La WebPartZoneCollection classe contiene una Item[String] proprietà.The WebPartZoneCollection class contains an Item[String] property. Questa proprietà consente di individuare un WebPartZone controllo all'interno della raccolta passando un identificatore di stringa.This property allows you to locate a WebPartZone control within the collection by passing in a string identifier. La zona viene individuata associando l'identificatore di stringa al valore della ID proprietà in una WebPartZoneBase zona.The zone is located by matching the string identifier to the value of the ID property on a WebPartZoneBase zone.

La WebPartZoneCollection classe dispone inoltre di diversi metodi utili per l'analisi o l'accesso al contenuto.The WebPartZoneCollection class also has several methods that are useful for examining or accessing its contents. Il Contains metodo determina se una determinata zona è presente nella raccolta.The Contains method determines whether a particular zone exists in the collection. Il CopyTo metodo copia la raccolta in una matrice di WebPartZoneBase oggetti.The CopyTo method copies the collection to an array of WebPartZoneBase objects. Infine, il IndexOf metodo restituisce l'indice di una particolare zona all'interno della raccolta.Finally, the IndexOf method returns the index of a particular zone within the collection.

Costruttori

WebPartZoneCollection()

Inizializza un'istanza vuota della classe WebPartZoneCollection.Initializes an empty instance of the WebPartZoneCollection class.

WebPartZoneCollection(ICollection)

Inizializza una nuova istanza della classe WebPartZoneCollection passando un insieme di oggetti WebPartZone.Initializes an instance of the WebPartZoneCollection class by passing in a collection of WebPartZone objects.

Proprietà

Count

Ottiene il numero di elementi contenuti nell'istanza di ReadOnlyCollectionBase.Gets the number of elements contained in the ReadOnlyCollectionBase instance.

(Ereditato da ReadOnlyCollectionBase)
InnerList

Ottiene l'elenco degli elementi contenuti nell'istanza di ReadOnlyCollectionBase.Gets the list of elements contained in the ReadOnlyCollectionBase instance.

(Ereditato da ReadOnlyCollectionBase)
Item[Int32]

Restituisce un membro specifico dell'insieme passando un Integer.Returns a specific member of the collection by passing in an integer.

Item[String]

Restituisce un membro specifico dell'insieme passando un identificatore univoco.Returns a specific member of the collection by passing in a unique identifier.

Metodi

Contains(WebPartZoneBase)

Restituisce un valore che indica se una particolare zona è inclusa nell'insieme.Returns a value indicating whether a particular zone exists in the collection.

CopyTo(WebPartZoneBase[], Int32)

Copia l'insieme in una matrice di oggetti WebPartZoneBase.Copies the collection to an array of WebPartZoneBase objects.

Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object.

(Ereditato da Object)
GetEnumerator()

Restituisce un enumeratore per lo scorrimento dell'istanza di ReadOnlyCollectionBase.Returns an enumerator that iterates through the ReadOnlyCollectionBase instance.

(Ereditato da ReadOnlyCollectionBase)
GetHashCode()

Funge da funzione hash predefinita.Serves as the default hash function.

(Ereditato da Object)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance.

(Ereditato da Object)
IndexOf(WebPartZoneBase)

Restituisce la posizione di un membro specifico dell'insieme.Returns the position of a particular member of the collection.

MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.Returns a string that represents the current object.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

ICollection.CopyTo(Array, Int32)

Copia l'intero oggetto ReadOnlyCollectionBase in un oggetto Array compatibile unidimensionale, a partire dall'indice specificato della matrice di destinazione.Copies the entire ReadOnlyCollectionBase to a compatible one-dimensional Array, starting at the specified index of the target array.

(Ereditato da ReadOnlyCollectionBase)
ICollection.IsSynchronized

Ottiene un valore che indica se l'accesso a un oggetto ReadOnlyCollectionBase è sincronizzato (thread-safe).Gets a value indicating whether access to a ReadOnlyCollectionBase object is synchronized (thread safe).

(Ereditato da ReadOnlyCollectionBase)
ICollection.SyncRoot

Ottiene un oggetto che può essere usato per sincronizzare l'accesso all'oggetto ReadOnlyCollectionBase.Gets an object that can be used to synchronize access to a ReadOnlyCollectionBase object.

(Ereditato da ReadOnlyCollectionBase)

Metodi di estensione

Cast<TResult>(IEnumerable)

Esegue il cast degli elementi di un oggetto IEnumerable nel tipo specificato.Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filtra gli elementi di un oggetto IEnumerable in base a un tipo specificato.Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Consente la parallelizzazione di una query.Enables parallelization of a query.

AsQueryable(IEnumerable)

Converte un oggetto IEnumerable in un oggetto IQueryable.Converts an IEnumerable to an IQueryable.

Si applica a

Vedi anche