ViewCollection 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.
Mewakili kontainer koleksi yang memungkinkan MultiView kontrol untuk mempertahankan daftar kontrol turunannya.
public ref class ViewCollection : System::Web::UI::ControlCollection
public class ViewCollection : System.Web.UI.ControlCollection
type ViewCollection = class
inherit ControlCollection
Public Class ViewCollection
Inherits ControlCollection
- Warisan
Contoh
Contoh kode berikut menunjukkan cara menambahkan View kontrol secara terprogram ke MultiView kontrol. Setelah setiap View kontrol dibuat, AddAt metode digunakan untuk menambahkan View kontrol ke ViewCollection kumpulan MultiView kontrol pada indeks yang ditentukan. Pengindeks Item[] digunakan untuk mengakses ID properti kontrol yang View disimpan dalam ViewCollection koleksi dan menampilkannya kepada pengguna.
<%@ 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>
<title>ViewCollection example</title>
<script runat="server">
Sub Button1_Click(ByVal Sender As Object, ByVal e As EventArgs)
' Create a MultiView control.
Dim MultiView1 As New MultiView
' Create a ViewCollection for the View
' controls contained in MultiView1.
Dim myViewCollection As New ViewCollection(MultiView1)
' Create a View control.
Dim View1 As New View
' Use a helper function to create the view.
View1 = CreateView("View1")
' Add View1 to myViewCollection at index 0.
myViewCollection.AddAt(0, View1)
' Create a second View control and
' add it to myViewCollection at index 1.
Dim View2 As New View
View2 = CreateView("View2")
myViewCollection.AddAt(1, View2)
' Create a third View control and
' add it to myViewCollection at index 0.
' Inserting View3 at index 0
' causes View1 to move to index 1
' and View2 to move to index 2.
Dim View3 As New View
View3 = CreateView("View3")
myViewCollection.AddAt(0, View3)
' Show the contents of myViewCollection on the page.
DisplayViewCollectionContents(myViewCollection)
End Sub
' A function to programmatically create a View control.
Private Function CreateView(ByVal viewId As String) As View
' Create a View control
Dim myView As New View
myView.ID = viewId
' Create a Panel control.
Dim Panel1 As New Panel
' Set the style properties for Panel1.
Panel1.Height = New Unit(150)
Panel1.Width = New Unit(150)
Panel1.BackColor = System.Drawing.Color.Azure
Panel1.BorderStyle = BorderStyle.Double
' Add Panel1 to the Controls collection
' of the View control.
myView.Controls.Add(Panel1)
' Create a Label control.
Dim Label1 As New Label
' Set the properties for Label1.
Label1.Text = "This is " + CStr(myView.ID)
' Add Label1 to the Controls collection
' of the Panel1 control.
Panel1.Controls.Add(Label1)
Return myView
End Function
' A sub-routine to display the contents of myViewCollection.
Sub DisplayViewCollectionContents(ByVal collection As ViewCollection)
' Use the Item property to access the ID of the View
' control at the specified index in the collection.
Label1.Text = "The view at index 0 is " + collection.Item(0).ID
Label2.Text = "The view at index 1 is " + collection.Item(1).ID
Label3.Text = "The view at index 2 is " + collection.Item(2).ID
End Sub
</script>
</head>
<body>
<form id="Form1" runat="server">
<h3>ViewCollection example</h3>
<asp:Button id="Button2"
Text="Show ViewCollection contents"
OnClick="Button1_Click"
runat="Server"/>
<br /><br />
<hr />
<asp:Label ID="Label1"
runat="Server">
</asp:Label><br /><br />
<asp:Label ID="Label2"
runat="Server">
</asp:Label><br /><br />
<asp:Label ID="Label3"
runat="Server">
</asp:Label><br /><br />
</form>
</body>
</html>
Keterangan
Kelas ViewCollection mewakili kontainer koleksi yang memungkinkan MultiView kontrol untuk mempertahankan daftar kontrol turunannya. MultiView Kontrol hanya View dapat berisi kontrol sebagai kontrol turunan.
Add Gunakan metode untuk menambahkan kontrol baru View ke ViewCollection koleksi di akhir array indeks ordinal. AddAt Gunakan metode untuk menambahkan kontrol baru di lokasi indeks tertentu. Gunakan pengindeks Item[] untuk mendapatkan View kontrol dari ViewCollection koleksi pada indeks tertentu, menggunakan notasi array sederhana.
Konstruktor
| Nama | Deskripsi |
|---|---|
| ViewCollection(Control) |
Menginisialisasi instans baru dari kelas ViewCollection. |
Properti
| Nama | Deskripsi |
|---|---|
| Count |
Mendapatkan jumlah kontrol server dalam ControlCollection objek untuk kontrol server ASP.NET yang ditentukan. (Diperoleh dari ControlCollection) |
| IsReadOnly |
Mendapatkan nilai yang menunjukkan apakah objek ControlCollection bersifat baca-saja. (Diperoleh dari ControlCollection) |
| IsSynchronized |
Mendapatkan nilai yang menunjukkan apakah objek disinkronkan ControlCollection . (Diperoleh dari ControlCollection) |
| Item[Int32] |
Mendapatkan referensi ke View kontrol di lokasi indeks yang ditentukan dalam ViewCollection koleksi. |
| Owner |
Mendapatkan kontrol server ASP.NET tempat objek berada ControlCollection . (Diperoleh dari ControlCollection) |
| SyncRoot |
Mendapatkan objek yang dapat digunakan untuk menyinkronkan akses ke kumpulan kontrol. (Diperoleh dari ControlCollection) |
Metode
| Nama | Deskripsi |
|---|---|
| Add(Control) |
Menambahkan kontrol yang ditentukan View ke koleksi. |
| AddAt(Int32, Control) |
Menambahkan kontrol yang ditentukan View ke koleksi di lokasi indeks yang ditentukan. |
| Clear() |
Menghapus semua kontrol dari objek kontrol ControlCollection server saat ini. (Diperoleh dari ControlCollection) |
| Contains(Control) |
Menentukan apakah kontrol server yang ditentukan berada di objek kontrol ControlCollection server induk. (Diperoleh dari ControlCollection) |
| CopyTo(Array, Int32) |
Menyalin kontrol anak yang disimpan dalam ControlCollection objek ke Array objek, dimulai dari lokasi indeks yang ditentukan di Array. (Diperoleh dari ControlCollection) |
| Equals(Object) |
Menentukan apakah objek yang ditentukan sama dengan objek saat ini. (Diperoleh dari Object) |
| GetEnumerator() |
Mengambil enumerator yang dapat melakukan iterasi melalui ControlCollection objek. (Diperoleh dari ControlCollection) |
| GetHashCode() |
Berfungsi sebagai fungsi hash default. (Diperoleh dari Object) |
| GetType() |
Mendapatkan Type instans saat ini. (Diperoleh dari Object) |
| IndexOf(Control) |
Mengambil indeks objek tertentu Control dalam koleksi. (Diperoleh dari ControlCollection) |
| MemberwiseClone() |
Membuat salinan dangkal dari Objectsaat ini. (Diperoleh dari Object) |
| Remove(Control) |
Menghapus kontrol server yang ditentukan dari objek kontrol ControlCollection server induk. (Diperoleh dari ControlCollection) |
| RemoveAt(Int32) |
Menghapus kontrol anak, di lokasi indeks yang ditentukan, dari ControlCollection objek. (Diperoleh dari ControlCollection) |
| ToString() |
Mengembalikan string yang mewakili objek saat ini. (Diperoleh dari Object) |
Metode Ekstensi
| Nama | Deskripsi |
|---|---|
| AsParallel(IEnumerable) |
Mengaktifkan paralelisasi kueri. |
| AsQueryable(IEnumerable) |
Mengonversi IEnumerable menjadi IQueryable. |
| Cast<TResult>(IEnumerable) |
Melemparkan elemen IEnumerable ke jenis yang ditentukan. |
| OfType<TResult>(IEnumerable) |
Memfilter elemen IEnumerable berdasarkan jenis tertentu. |