다음을 통해 공유


ViewCollection.Item[Int32] 속성

정의

View 컬렉션의 지정된 인덱스에서 ViewCollection 컨트롤에 대한 참조를 가져옵니다.

public:
 property System::Web::UI::WebControls::View ^ default[int] { System::Web::UI::WebControls::View ^ get(int i); };
public System.Web.UI.WebControls.View this[int i] { get; }
member this.Item(int) : System.Web.UI.WebControls.View
Default Public ReadOnly Property Item(i As Integer) As View

매개 변수

i
Int32

View에서 ViewCollection 컨트롤의 위치를 지정하는 서수 인덱스 값입니다.

속성 값

View

ViewViewCollection 컨트롤에 대한 참조입니다.

예제

다음 코드 예제에서는 프로그래밍 방식으로 추가 하는 방법을 보여 줍니다 View 컨트롤을 MultiView 제어 합니다. 각 View 컨트롤을 만든를 AddAt 메서드 추가를 사용 하는 View 컨트롤을 ViewCollection 의 컬렉션을 MultiView 컨트롤의 지정 된 인덱스. Item[] 인덱서를 사용할에 액세스 하려면를 ID 의 속성을 View 컨트롤에 저장는 ViewCollection 컬렉션 하 고 사용자에 게 표시할.

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

설명

이 인덱서를 사용 하 여는 View 에서 제어를 ViewCollection 간단한 배열 표기법을 사용 하 여, 지정 된 인덱스의 컬렉션입니다.

적용 대상

추가 정보