ControlCollection.Clear メソッド
アセンブリ: System.Web (system.web.dll 内)


Control.CreateChildControls メソッドおよび DataBind メソッドをオーバーライドする場合は、このメソッドを使用してカスタム コントロールの ControlCollection を空にします。template 宣言された複合コントロール、または template 宣言されたデータ バインド コントロールを開発する場合にこの操作を行います。

Control.CreateChildControls メソッドをオーバーライドし、Clear メソッドを使用して、以前 ControlCollection オブジェクト内にあった子コントロールをすべて削除する方法を次のコード例に示します。この例の場合は、コントロールの ControlCollection にある古いオブジェクトが誤って表示されないように、この操作を実行する必要があります。
' Override to create repeated items. Protected Overrides Sub CreateChildControls() Dim O As Object = ViewState("NumItems") If Not (O Is Nothing) ' Clear any existing child controls. Controls.Clear() Dim I As Integer Dim NumItems As Integer = CInt(O) For I = 0 To NumItems - 1 ' Create an item. Dim Item As RepeaterItemVB = New RepeaterItemVB(I, Nothing) ' Initialize the item from the template. ItemTemplate.InstantiateIn(Item) ' Add the item to the ControlCollection. Controls.Add(Item) Next End If End Sub
// Override to create repeated items. protected override void CreateChildControls() { object o = ViewState["NumItems"]; if (o != null) { // Clear any existing child controls. Controls.Clear(); int numItems = (int)o; for (int i=0; i < numItems; i++) { // Create an item. RepeaterItem item = new RepeaterItem(i, null); // Initialize the item from the template. ItemTemplate.InstantiateIn(item); // Add the item to the ControlCollection. Controls.Add(item); } } }
// Override to create repeated items. protected void CreateChildControls() { Object o = get_ViewState().get_Item("NumItems"); if (o != null) { // Clear any existing child controls. get_Controls().Clear(); int numItems = Convert.ToInt32(o); for (int i = 0; i < numItems; i++) { // Create an item. RepeaterItem item = new RepeaterItem(i, null); // Initialize the item from the template. get_ItemTemplate().InstantiateIn(item); // Add the item to the ControlCollection. get_Controls().Add(item); } } } //CreateChildControls

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.Clear メソッドを検索する場合は、下記のリンクをクリックしてください。

- ControlCollection.Clear メソッドのページへのリンク