2010-05-14 4 views

답변

2

다음은 모든 하위 컨트롤을 나열해야합니다.

IEnumerable<Control> GetAllChildControls(ControlCollection controls) 
{ 
    foreach(Control c in controls) 
    { 
    yield return c; 

    if(c.Controls.Count > 0) 
    { 
     foreach(Control control in GetAllChildControls(c.Controls)) 
     { 
     yield return control; 
     } 
    } 
    } 
} 
1

컨트롤 속성에는 현재 컨트롤의 직접 자식 만 포함됩니다. 페이지의 모든 컨트롤을 반복하려면 페이지의 하위 항목을 반복하고 하위 항목을 반복적으로 반복 한 다음 하위 항목을 반복해야합니다. 재귀 적 방법이이를 구현하는 가장 간단한 방법입니다.

관련 문제