ControlCollection.Add(Control) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
컬렉션에 지정된 Control 개체를 추가합니다.
public:
virtual void Add(System::Web::UI::Control ^ child);
public virtual void Add(System.Web.UI.Control child);
abstract member Add : System.Web.UI.Control -> unit
override this.Add : System.Web.UI.Control -> unit
Public Overridable Sub Add (child As Control)
매개 변수
예외
매개 변수는 child 컨트롤을 지정하지 않습니다.
읽기 ControlCollection 전용입니다.
예제
다음 코드 예제에서는 이 메서드를 사용하여 Add 서버 컨트롤의 뷰 상태에서 가져온 일련의 템플릿 항목을 사용자 지정 템플릿 형식 컨트롤에 추가합니다.
// 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
설명
새 컨트롤이 서수 인덱스 배열의 끝에 추가됩니다. 컨트롤은 ASP.NET 서버 컨트롤의 인스턴스, 사용자가 만든 사용자 지정 서버 컨트롤 또는 리터럴 컨트롤일 수 있습니다.
특정 인덱스 위치의 컬렉션에 컨트롤을 추가하려면 메서드를 AddAt 사용합니다.