ControlCollection.AddAt(Int32, Control) Methode

Definition

Fügt das angegebene Control Objekt der Auflistung an der angegebenen Indexposition hinzu.

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)

Parameter

index
Int32

Die Position im Array, an dem das untergeordnete Steuerelement hinzugefügt werden soll.

child
Control

Das Control , das der Auflistung hinzugefügt werden soll.

Ausnahmen

Der child Parameter gibt kein Steuerelement an.

Der index Parameter ist kleiner als Null oder größer als die Count Eigenschaft.

Dies ControlCollection ist schreibgeschützt.

Beispiele

Im folgenden Codebeispiel wird die AddAt Methode verwendet, um einen neuen LiteralControl Namen ChildControl2 zu erstellen und der myButton Auflistung des Steuerelements ControlCollection am Indexspeicherort von 1 hinzuzufügen.

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

Hinweise

Das hinzugefügte Steuerelement kann eine Instanz eines beliebigen ASP.NET Serversteuerelements, ein benutzerdefiniertes Serversteuerelement, das Sie erstellen, oder ein Literalsteuerelement sein.

Gilt für:

Weitere Informationen