ControlCollection.Clear 메서드

정의

현재 서버 컨트롤의 ControlCollection 개체에서 컨트롤을 모두 제거합니다.

public:
 virtual void Clear();
public virtual void Clear ();
abstract member Clear : unit -> unit
override this.Clear : unit -> unit
Public Overridable Sub Clear ()

예제

다음 코드 예제에서는 재정의 하는 방법을 보여 줍니다 합니다 Control.CreateChildControls 메서드를 사용 하 여를 Clear 에서 모든 자식 컨트롤이 이전에 삭제 하는 방법의 ControlCollection 개체입니다. 이 경우 변경 해야 할 개체에 컨트롤의 오래 된 있도록 ControlCollection 부적절 하 게 표시 되지 않습니다.

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

설명

이 메서드를 사용 하 여 사용자 지정 컨트롤의 빈 ControlCollection 재정의 하는 경우는 Control.CreateChildControlsDataBind 메서드. 복합, 템플릿 기반 컨트롤 또는 템플릿 데이터 바인딩된 컨트롤을 개발 하는 경우이 작업을 수행 합니다.

적용 대상

추가 정보