如何在更新面板中实现GetEnumerator方法?

时间:2011-12-16 19:50:23

标签: c# updatepanel

我想迭代更新面板的各种控件。在使用ID进行控制迭代时,我想删除一些控件。

但我不知道如何使用GetEnumerator方法迭代更新面板的控件?
如果我们可以通过其他方式进行迭代,请告诉我。

2 个答案:

答案 0 :(得分:0)

无法遍历updatepanel的Controls集合:

 foreach(var control in myUpdatePanel.Controls) {
      ...
 }

答案 1 :(得分:0)

您可以循环ControlCollection。

请记住,如果这些控件位于面板中,则可以嵌套这些控件。

private void RecusiceControls(ControlCollection controls)
        {
            foreach (Control control in controls)
            {
                RecusiceControls((ControlCollection)control.Controls);
                if (control is Button) // whatever the control is you are looking for
                {
                }
            }
        }