ControlCollection.IndexOf(Control) Método

Definición

Recupera el índice de un objeto Control especificado en la colección.Retrieves the index of a specified Control object in the collection.

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

Parámetros

value
Control

El objeto Control para el que se devuelve el índice.The Control for which the index is returned.

Devoluciones

Int32

Índice del control de servidor especificado.The index of the specified server control. Si el control de servidor no es en la actualidad un miembro de la colección, devuelve -1.If the server control is not currently a member of the collection, it returns -1.

Ejemplos

En el ejemplo de código siguiente IndexOf se usa el método para escribir la ubicación de índice de un control, myLiteralControl , en la ControlCollection colección de un Button control denominado myButton .The following code example uses the IndexOf method to write the index location of a control, myLiteralControl, in the ControlCollection collection of a Button control named 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))

Comentarios

Utilice este método para determinar la ubicación de índice del control de servidor especificado en el ControlCollection objeto.Use this method to determine the index location of the specified server control in the ControlCollection object.

Se aplica a

Consulte también