ControlCollection.AddAt(Int32, Control) Méthode

Définition

Ajoute l'objet Control spécifié à la collection à l'emplacement d'index spécifié.

public:
 virtual void AddAt(int index, System::Web::UI::Control ^ child);
public virtual void AddAt (int index, System.Web.UI.Control child);
abstract member AddAt : int * System.Web.UI.Control -> unit
override this.AddAt : int * System.Web.UI.Control -> unit
Public Overridable Sub AddAt (index As Integer, child As Control)

Paramètres

index
Int32

Position dans le tableau où ajouter le contrôle enfant.

child
Control

Objet Control à ajouter à la collection.

Exceptions

Le paramètre child ne spécifie pas de contrôle.

Le paramètre index est inférieur à zéro ou supérieur à la propriété Count.

ControlCollection est en lecture seule.

Exemples

L’exemple de code suivant utilise la AddAt méthode pour créer un nouveau LiteralControl nommé ChildControl2 et l’ajouter à la myButton collection du ControlCollection contrôle à l’emplacement d’index 1.

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

Remarques

Le contrôle ajouté peut être une instance de n’importe quel contrôle serveur ASP.NET, un contrôle serveur personnalisé que vous créez ou un contrôle littéral.

S’applique à

Voir aussi