ControlCollection.Item プロパティ
アセンブリ: System.Web (system.web.dll 内)

- index
ControlCollection 内のサーバー コントロールの位置。
コントロールへの参照。


Remove メソッド呼び出しで削除される子コントロールのインデックス位置を、Item プロパティを使用して指定するコード例を次に示します。これは、myButton.Controls.Remove 構文で実行されています。
<html> <head> <script language="VB" runat="server"> Sub Page_Load( Sender as Object,e as EventArgs ) Response.Write("<h2><Center><b><font color=blue> Sample for ControlCollection Class</font></h2></Center></b>") Dim myLiteralControl as LiteralControl=new LiteralControl("ChildControl1") myButton.Controls.Add(myLiteralControl) myButton.Controls.AddAt(1,new LiteralControl("ChildControl2")) Dim myControlCollectionArray as System.Array = _ Array.CreateInstance(GetType(object) ,myButton.Controls.Count) myButton.Controls.CopyTo(myControlCollectionArray,0) Dim myEnumerator1 as IEnumerator= myControlCollectionArray.GetEnumerator() while (myEnumerator1.MoveNext()) Dim myObject as object = myEnumerator1.Current if(myObject.GetType().Equals(GetType(LiteralControl))) Dim childControl as LiteralControl=CType(myEnumerator1.Current ,LiteralControl) Response.Write("<b><br> This is the text of the child Control </b>:" _ + Server.HtmlEncode(childControl.Text)) End If End While myButton.Controls.Remove(myButton.Controls(0)) Response.Write("<br><b>ChildControl1 is removed</b>") Response.Write("<br><b> The count of ControlCollection </b>" _ +myButton.Controls.Count.ToString()) myButton.Controls.Clear() End Sub </script> </head> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:Button ID="myButton" Text="Sample ServerControl" Runat="server"></asp:Button> </form> </body> </html>
<html> <head> <script language="cs" runat="server"> void Page_Load(Object Sender,EventArgs e) { Response.Write("<h2><Center><b><font color=blue> Sample for ControlCollection Class</font></h2></Center></b>"); LiteralControl myLiteralControl=new LiteralControl("ChildControl1"); myButton.Controls.Add(myLiteralControl); myButton.Controls.AddAt(1,new LiteralControl("ChildControl2")); System.Array myControlCollectionArray =Array.CreateInstance(typeof(object) ,myButton.Controls.Count); myButton.Controls.CopyTo(myControlCollectionArray,0); IEnumerator myEnumerator1= myControlCollectionArray.GetEnumerator(); while (myEnumerator1.MoveNext()) { object myObject = myEnumerator1.Current; if(myObject.GetType().Equals(typeof(LiteralControl))) { LiteralControl childControl=(LiteralControl)myEnumerator1.Current; Response.Write("<b><br> This is the text of the child Control </b>:" + Server.HtmlEncode(childControl.Text)); } } myButton.Controls.Remove(myButton.Controls[0]); Response.Write("<br><b>ChildControl1 is removed</b>"); Response.Write("<br><b> The count of ControlCollection </b>" +myButton.Controls.Count); myButton.Controls.Clear(); } </script> </head> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:Button ID="myButton" Text="Sample ServerControl" Runat="server"></asp:Button> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からControlCollection.Item プロパティを検索する場合は、下記のリンクをクリックしてください。

- ControlCollection.Item プロパティのページへのリンク