ControlCollection.IndexOf(Control) 메서드

정의

컬렉션에서 지정된 Control 개체의 인덱스를 검색합니다.

public:
 virtual int IndexOf(System::Web::UI::Control ^ value);
public virtual int IndexOf (System.Web.UI.Control value);
abstract member IndexOf : System.Web.UI.Control -> int
override this.IndexOf : System.Web.UI.Control -> int
Public Overridable Function IndexOf (value As Control) As Integer

매개 변수

value
Control

인덱스가 반환된 Control입니다.

반환

Int32

지정된 서버 컨트롤의 인덱스입니다. 서버 컨트롤이 현재 컬렉션의 멤버가 아니면 -1을 반환합니다.

예제

다음 코드 예제에서는 IndexOf 컨트롤의 인덱스를 작성 하는 방법 myLiteralControlControlCollection 의 컬렉션을 Button 라는 컨트롤 myButton합니다.

// Create a LiteralControl and use the Add method to add it
// to a button's ControlCollection, then use the AddAt method
// to add another LiteralControl to the collection at the
// index location of 1.
LiteralControl myLiteralControl = new LiteralControl("ChildControl1");
myButton.Controls.Add(myLiteralControl);
myButton.Controls.AddAt(1,new LiteralControl("ChildControl2"));
Response.Write("<b>ChildControl2 is added at index 1</b>");

// Get the Index location of the myLiteralControl LiteralControl
// and write it to the page.
Response.Write("<br /><b>Index of the ChildControl myLiteralControl is " +
    "</b>" + myButton.Controls.IndexOf(myLiteralControl));
' Create a LiteralControl and use the Add method to add it
' to a button's ControlCollection, then use the AddAt method
' to add another LiteralControl to the collection at the
' index location of 1.
Dim myLiteralControl As LiteralControl =  _
    new LiteralControl("ChildControl1")
myButton.Controls.Add(myLiteralControl)
myButton.Controls.AddAt(1,new LiteralControl("ChildControl2"))
Response.Write("<b>ChildControl2 is added at index 1</b>")

' Get the Index location of the myLiteralControl LiteralControl
' and write it to the page.
Response.Write("<br /><b>Index of the ChildControl myLiteralControl is </b>" & _
                 myButton.Controls.IndexOf(myLiteralControl))

설명

이 메서드를 사용 하 여 지정 된 서버 컨트롤의 인덱스 위치를 결정 하는 ControlCollection 개체입니다.

적용 대상

추가 정보