WebPartZoneCollection Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Berisi kumpulan WebPartZone kontrol baca-saja.
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
- Warisan
Contoh
Contoh kode berikut menunjukkan penggunaan WebPartZoneCollection kelas . Contoh kode berisi tiga bagian: dua bagian kode, dan penjelasan tentang cara menjalankan contoh.
Bagian pertama dari contoh kode adalah halaman Web yang berisi tiga WebPartZone kontrol, yang masing-masing berisi satu kontrol server. Meskipun kontrol server ini semuanya merupakan kontrol ASP.NET standar, kontrol tersebut dapat bertindak sebagai WebPart kontrol pada durasi karena ditempatkan dalam WebPartZone zona.
<%@ 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>
Bagian kedua dari contoh kode adalah kelas parsial yang berisi kode untuk menunjukkan penggunaan WebPartZoneCollection kelas . Kode ini menangani kejadian untuk halaman Web.
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
Muat halaman di browser. Tiga WebPartZone zona terlihat dengan kontrol server yang terkandung. Di dekat bagian bawah halaman ada beberapa tombol, yang masing-masing menunjukkan beberapa aspek bekerja dengan WebPartZoneCollection objek . Klik setiap tombol untuk melihat efeknya pada zona dan kontennya. Untuk melihat kode yang terkait dengan setiap tombol yang menunjukkan beberapa aspek WebPartZoneCollection objek, lihat kode dalam file kelas parsial yang dirujuk di atas sebagai bagian kedua dari contoh kode ini.
Keterangan
Kelas WebPartZoneCollection berisi kumpulan WebPartZone kontrol yang ada pada halaman Bagian Web. Ini digunakan terutama oleh WebPartManager kontrol untuk melacak dan mengelola semua zona. WebPartManager Kontrol menyimpan referensi ke kumpulan zona pada halaman di properti baca-sajaZones.
Kelas WebPartZoneCollection ini berguna ketika Anda ingin melakukan operasi di beberapa zona atau kontennya secara bersamaan, atau ketika Anda perlu menemukan zona tertentu dan memeriksa atau mengubah kontennya. Meskipun kumpulan zona itu sendiri bersifat baca-saja dan Anda tidak dapat mengubah ukuran objek koleksi itu sendiri, Anda masih bisa mendapatkan referensi ke zona individual dalam koleksi, dan ketika Anda memiliki referensi ke objek zona individual, Anda dapat mengubah nilai propertinya.
Kelas ini WebPartZoneCollection memiliki dua konstruktor. Yang pertama, WebPartZoneCollection(), hanya menginisialisasi instans kosong dari yang baru WebPartZoneCollection. Yang kedua, WebPartZoneCollection(ICollection), menginisialisasi koleksi dengan melewati kumpulan zona yang ada.
Kelas WebPartZoneCollection berisi Item[] properti . Properti ini memungkinkan Anda menemukan WebPartZone kontrol dalam koleksi dengan meneruskan pengidentifikasi string. Zona ini terletak dengan mencocokkan pengidentifikasi string dengan nilai ID properti pada WebPartZoneBase zona.
Kelas ini WebPartZoneCollection juga memiliki beberapa metode yang berguna untuk memeriksa atau mengakses kontennya. Metode menentukan Contains apakah zona tertentu ada dalam koleksi. Metode CopyTo menyalin koleksi ke array WebPartZoneBase objek. Akhirnya, IndexOf metode mengembalikan indeks zona tertentu dalam koleksi.
Konstruktor
WebPartZoneCollection() |
Menginisialisasi instans WebPartZoneCollection kosong kelas. |
WebPartZoneCollection(ICollection) |
Menginisialisasi instans WebPartZoneCollection kelas dengan meneruskan kumpulan WebPartZone objek. |
Properti
Count |
Mendapatkan jumlah elemen yang terkandung dalam ReadOnlyCollectionBase instans. (Diperoleh dari ReadOnlyCollectionBase) |
InnerList |
Mendapatkan daftar elemen yang terkandung dalam ReadOnlyCollectionBase instans. (Diperoleh dari ReadOnlyCollectionBase) |
Item[Int32] |
Mengembalikan anggota koleksi tertentu dengan meneruskan bilangan bulat. |
Item[String] |
Mengembalikan anggota koleksi tertentu dengan meneruskan pengidentifikasi unik. |
Metode
Contains(WebPartZoneBase) |
Mengembalikan nilai yang menunjukkan apakah zona tertentu ada dalam koleksi. |
CopyTo(WebPartZoneBase[], Int32) |
Menyalin koleksi ke array WebPartZoneBase objek. |
Equals(Object) |
Menentukan apakah objek yang ditentukan sama dengan objek saat ini. (Diperoleh dari Object) |
GetEnumerator() |
Mengembalikan enumerator yang berulang melalui ReadOnlyCollectionBase instans. (Diperoleh dari ReadOnlyCollectionBase) |
GetHashCode() |
Berfungsi sebagai fungsi hash default. (Diperoleh dari Object) |
GetType() |
Mendapatkan dari instans Type saat ini. (Diperoleh dari Object) |
IndexOf(WebPartZoneBase) |
Mengembalikan posisi anggota koleksi tertentu. |
MemberwiseClone() |
Membuat salinan dangkal dari saat ini Object. (Diperoleh dari Object) |
ToString() |
Mengembalikan string yang mewakili objek saat ini. (Diperoleh dari Object) |
Implementasi Antarmuka Eksplisit
ICollection.CopyTo(Array, Int32) |
Menyalin seluruh ReadOnlyCollectionBase ke satu dimensi Arrayyang kompatibel, dimulai dari indeks array target yang ditentukan. (Diperoleh dari ReadOnlyCollectionBase) |
ICollection.IsSynchronized |
Mendapatkan nilai yang menunjukkan apakah akses ke ReadOnlyCollectionBase objek disinkronkan (utas aman). (Diperoleh dari ReadOnlyCollectionBase) |
ICollection.SyncRoot |
Mendapatkan objek yang dapat digunakan untuk menyinkronkan akses ke ReadOnlyCollectionBase objek. (Diperoleh dari ReadOnlyCollectionBase) |
Metode Ekstensi
Cast<TResult>(IEnumerable) |
Mentransmisikan elemen dari ke IEnumerable jenis yang ditentukan. |
OfType<TResult>(IEnumerable) |
Memfilter elemen berdasarkan IEnumerable jenis yang ditentukan. |
AsParallel(IEnumerable) |
Mengaktifkan paralelisasi kueri. |
AsQueryable(IEnumerable) |
Mengonversi menjadi IEnumerableIQueryable. |