ControlCollection.IndexOf(Control) Methode

Definitie

Haalt de index van een opgegeven Control object in de verzameling op.

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

Parameters

value
Control

De Control index waarvoor de index wordt geretourneerd.

Retouren

De index van het opgegeven serverbeheer. Als het serverbesturingselement momenteel geen lid is van de verzameling, wordt -1 geretourneerd.

Voorbeelden

In het volgende codevoorbeeld wordt de IndexOf methode gebruikt om de indexlocatie van een besturingselement te schrijven, myLiteralControlin de verzameling van een Button besturingselement met de ControlCollection naammyButton.

// 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))

Opmerkingen

Gebruik deze methode om de indexlocatie van het opgegeven serverbeheer in het ControlCollection object te bepalen.

Van toepassing op

Zie ook