有效的数据源必须实现ilistsource或ienumerable [英] A valid data source must implement either ilistsource or ienumerable

查看:146
本文介绍了有效的数据源必须实现ilistsource或ienumerable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不清楚为什么以下代码返回有效数据源必须实现IListSource或IEnumerable



Not clear why following code returns "A valid data source must implement either IListSource or IEnumerable"

public class CGroup<TKey, TValue> 
{
  public TKey Key { get; set; }
  public IEnumerable<TValue> Values { get; set; }
}

//AIT is declared class
var cg = new CGroup<string, AIT>();
cg.Key = "Key Value";
//line below raises error, also tried new List<AIT>();
//Empty list is fine
cg.Values = new List<AIT>(){};
aRepeater.DataSource = cg;
aRepeater.DataBind();





感谢任何输入



我尝试了什么:



我尝试以不同的方式为cg.Values声明一个空列表,但仍然是错误。



Appreciate any input

What I have tried:

I tried declaring an empty list for cg.Values in different ways but still errors.

推荐答案

它应该是

it should be
aRepeater.DataSource = cg.Values;



,因为属性给出 List ,其类型为 IEnumerable interface


since Values property gives the List which is of type IEnumerable interface


不幸的是,我找不到解决方案,所以不要试图用键值创建一个空的数据源(希望键值显示为空在列表中,我改为将数据源设置为null并使用标签显示空。
Unfortunately, I couldn't find the solution for this so instead of trying to create an empty datasource with a key value (was hoping the key value would display "empty" in the list), I instead set the datasource to null and used labels to display "empty".


这篇关于有效的数据源必须实现ilistsource或ienumerable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆