如何在 CreateChildControls GridView 中迭代 IEnumerable dataSource
我可以获取枚举器和当前对象,但我不知道该对象包含什么,所以当您不知道类型并写出其中的值时,如何迭代集合。示例代码会很好请
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我在你的另一个问题中所说的,你的问题的简短答案是“反思”。这就是标准数据绑定工具发挥其魔力的方式。
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.