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.CreateChildControls 할 때 해당 컨트롤을 비울 수 DataBind 있습니다. 복합, 템플릿 기반 컨트롤 또는 템플릿 기반 데이터 바인딩된 컨트롤을 개발할 때 이 작업을 수행합니다.

적용 대상

추가 정보