如何在 CreateChildControls GridView 中迭代 IEnumerable dataSource

发布于 2024-12-23 12:13:39 字数 536 浏览 2 评论 0原文

我可以获取枚举器和当前对象,但我不知道该对象包含什么,所以当您不知道类型并写出其中的值时,如何迭代集合。示例代码会很好请

protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
    {
        // Call base method and get number of rows
        int numRows = base.CreateChildControls(dataSource, dataBinding);

        IEnumerator enumerator = dataSource.GetEnumerator();
        while(enumerator.MoveNext()
        {
            object obj = enumerator.Currnet as object;   
        }

        return numRows;
    }
}

I can get the enumerator and the Current object but I don't know what the object contains so how do i iterate over a collection when you don't know the type and write out there values. Sample code would be great please

protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
    {
        // Call base method and get number of rows
        int numRows = base.CreateChildControls(dataSource, dataBinding);

        IEnumerator enumerator = dataSource.GetEnumerator();
        while(enumerator.MoveNext()
        {
            object obj = enumerator.Currnet as object;   
        }

        return numRows;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

狼亦尘 2024-12-30 12:13:39

正如我在你的另一个问题中所说的,你的问题的简短答案是“反思”。这就是标准数据绑定工具发挥其魔力的方式。

As I said in your other question, the short answer to your question is "reflection." That's how the standard databinding tools work their magic.

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