在转发器中递归提取动态创建的控件,第二部分

发布于 2024-10-08 15:17:11 字数 854 浏览 0 评论 0原文

公平地说,这是 使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

把昨日还给我 2024-10-15 15:17:11

Have you checked the Repeater.Items property?

虚拟世界 2024-10-15 15:17:11

已解决...PEBKAC

REsolved ... PEBKAC

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文