ControlCollection.AddAt(Int32, Control) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在指定索引位置將指定的 Control 物件加入集合。
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)
參數
- index
- Int32
陣列中要加入子控制項的位置。
例外狀況
child
參數不指定控制項。
index
參數小於零或大於 Count 屬性。
範例
下列程式碼範例會 AddAt 使用 方法來建立名為 的新 LiteralControl , ChildControl2
並將它新增至 myButton
控制項的 ControlCollection 集合中,其索引位置為 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))
備註
新增的控制項可以是任何 ASP.NET 伺服器控制項、您所建立的自訂伺服器控制項或常值控制項的實例。