ViewCollection クラス

定義

MultiView コントロールが子コントロールの一覧を維持できるようにするコレクション コンテナーを表します。

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
継承
ViewCollection

次のコード例では、MultiView コントロールにView コントロールをプログラムで追加する方法を示します。 各View コントロールが作成されると、AddAt メソッドを使用して、指定したインデックス位置にあるMultiView コントロールのViewCollection コレクションにView コントロールを追加します。 Item[] インデクサーは、ViewCollection コレクションに格納されているView コントロールのID プロパティにアクセスし、ユーザーに表示するために使用されます。

<%@ 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>

注釈

ViewCollection クラスは、MultiView コントロールが子コントロールの一覧を維持できるようにするコレクション コンテナーを表します。 MultiView コントロールには、子コントロールとしてViewコントロールのみを含めることができます。

Add メソッドを使用して、序数インデックス配列の末尾にあるViewCollection コレクションに新しいView コントロールを追加します。 AddAt メソッドを使用して、特定のインデックス位置に新しいコントロールを追加します。 Item[] インデクサーを使用して、単純な配列表記を使用して、指定したインデックス位置にあるViewCollection コレクションからView コントロールを取得します。

コンストラクター

名前 説明
ViewCollection(Control)

ViewCollection クラスの新しいインスタンスを初期化します。

プロパティ

名前 説明
Count

指定した ASP.NET サーバー コントロールの ControlCollection オブジェクト内のサーバー コントロールの数を取得します。

(継承元 ControlCollection)
IsReadOnly

ControlCollection オブジェクトが読み取り専用かどうかを示す値を取得します。

(継承元 ControlCollection)
IsSynchronized

ControlCollection オブジェクトが同期されているかどうかを示す値を取得します。

(継承元 ControlCollection)
Item[Int32]

ViewCollection コレクション内の指定したインデックス位置にあるView コントロールへの参照を取得します。

Owner

ControlCollection オブジェクトが属する ASP.NET サーバー コントロールを取得します。

(継承元 ControlCollection)
SyncRoot

コントロールのコレクションへのアクセスを同期するために使用できるオブジェクトを取得します。

(継承元 ControlCollection)

メソッド

名前 説明
Add(Control)

指定した View コントロールをコレクションに追加します。

AddAt(Int32, Control)

指定した View コントロールを、指定したインデックス位置にあるコレクションに追加します。

Clear()

現在のサーバー コントロールの ControlCollection オブジェクトからすべてのコントロールを削除します。

(継承元 ControlCollection)
Contains(Control)

指定したサーバー コントロールが親サーバー コントロールの ControlCollection オブジェクト内にあるかどうかを判断します。

(継承元 ControlCollection)
CopyTo(Array, Int32)

ControlCollection内の指定したインデックス位置から、Array オブジェクトに格納されている子コントロールをArray オブジェクトにコピーします。

(継承元 ControlCollection)
Equals(Object)

指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetEnumerator()

ControlCollection オブジェクトを反復処理できる列挙子を取得します。

(継承元 ControlCollection)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IndexOf(Control)

コレクション内の指定した Control オブジェクトのインデックスを取得します。

(継承元 ControlCollection)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
Remove(Control)

指定したサーバー コントロールを親サーバー コントロールの ControlCollection オブジェクトから削除します。

(継承元 ControlCollection)
RemoveAt(Int32)

指定したインデックス位置にある子コントロールを ControlCollection オブジェクトから削除します。

(継承元 ControlCollection)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

拡張メソッド

名前 説明
AsParallel(IEnumerable)

クエリの並列化を有効にします。

AsQueryable(IEnumerable)

IEnumerableIQueryableに変換します。

Cast<TResult>(IEnumerable)

IEnumerable の要素を指定した型にキャストします。

OfType<TResult>(IEnumerable)

指定した型に基づいて、IEnumerable の要素をフィルター処理します。

適用対象

こちらもご覧ください