【发布时间】:2010-12-16 17:19:37
【问题描述】:
说句公道话,这是Using C# to recursively get a collection of controls from a controlcollection 的第二部分 - 我没有在旧问题上堆砌另一个问题,而是创建了一个新问题。这是我正在使用的代码:
private void GetControlList<T>(ControlCollection controlCollection, ref List<T> resultCollection) where T : Control
{
foreach (Control control in controlCollection)
{
if (control.HasControls())
GetControlList(control.Controls, ref resultCollection);
else if (control is T)
resultCollection.Add((T)control);
}
}
并在提交表单时这样调用
List<CheckBox> checkboxes = new List<CheckBox>();
GetControlList(RepeaterCapability.Controls, ref checkboxes);
问题是,当我在转发器 OnItemDataBound 事件期间明确添加了几个时,我没有得到任何结果。有什么想法吗?
【问题讨论】: