次の方法で共有


ControlCollection.AddAt メソッド

指定したインデックス位置に、指定した Control オブジェクトを追加します。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
Public Overridable Sub AddAt ( _
    index As Integer, _
    child As Control _
)
'使用
Dim instance As ControlCollection
Dim index As Integer
Dim child As Control

instance.AddAt(index, child)
public virtual void AddAt (
    int index,
    Control child
)
public:
virtual void AddAt (
    int index, 
    Control^ child
)
public void AddAt (
    int index, 
    Control child
)
public function AddAt (
    index : int, 
    child : Control
)
適用できません。

パラメータ

  • index
    子コントロールを追加する配列内の位置。
  • child
    コレクションに追加する Control

例外

例外の種類 条件

ArgumentNullException

child パラメータがコントロールを指定しません。

ArgumentOutOfRangeException

index パラメータが 0 未満か、ControlCollection.Count プロパティより大きい値です。

HttpException

ControlCollection は読み取り専用です。

解説

追加されるコントロールは、ASP.NET サーバー コントロール、作成したカスタム サーバー コントロール、リテラル コントロールのいずれかのインスタンスにすることができます。

使用例

AddAt メソッドを使用して、ChildControl2 という名前の新しい LiteralControl を作成し、インデックス位置 1 にある myButton コントロールの ControlCollection コレクションに追加するコード例を次に示します。

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

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

ControlCollection クラス
ControlCollection メンバ
System.Web.UI 名前空間
Control.Controls プロパティ
Add