在转发器中递归提取动态创建的控件,第二部分
公平地说,这是 使用 C# 从控件集合中递归获取控件集合 - 我没有将另一个问题堆放在旧问题上,而是创建了一个新问题。这是我正在使用的代码:
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 事件期间明确添加几个时,我没有得到任何结果。有什么想法吗?
To be fair, this is a part two follow up to Using C# to recursively get a collection of controls from a controlcollection - and rather than heap another question onto the old one, I created a new one. Here is the code that I'm using:
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);
}
}
and is involked like this when the form is submitted
List<CheckBox> checkboxes = new List<CheckBox>();
GetControlList(RepeaterCapability.Controls, ref checkboxes);
The problem is that I don't get any results when I clearly added several during the repeater OnItemDataBound event. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您检查过 Repeater.Items财产?
Have you checked the Repeater.Items property?
已解决...PEBKAC
REsolved ... PEBKAC