ControlCollection.AddAt(Int32, Control) Método

Definición

Agrega el objeto especificado Control a la colección en la ubicación de índice especificada.

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)

Parámetros

index
Int32

Ubicación de la matriz en la que se va a agregar el control secundario.

child
Control

que Control se va a agregar a la colección.

Excepciones

El child parámetro no especifica un control .

El index parámetro es menor que cero o mayor que la Count propiedad .

es ControlCollection de solo lectura.

Ejemplos

En el ejemplo de código siguiente se usa el AddAt método para crear un nuevo denominado ChildControl2LiteralControl y agregarlo a la myButton colección del ControlCollection control en la ubicación del índice de 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))

Comentarios

El control agregado puede ser una instancia de cualquier control de servidor ASP.NET, un control de servidor personalizado que cree o un control literal.

Se aplica a

Consulte también