C# 如果字典是我的数据源的一个属性,我可以使用一个特定的字典键作为DataTextField吗?
粗略类架构:C# 如果字典是我的数据源的一个属性,我可以使用一个特定的字典键作为DataTextField吗?,c#,dictionary,telerik,rad-controls,datatextfield,C#,Dictionary,Telerik,Rad Controls,Datatextfield,粗略类架构: public class Entity { public Guid ID; public Dictionary<String, object> Attributes; } 我想在组合框中显示键为listname的属性值作为DataTextField,但我不知道如何执行此操作。我已经在这里进行了检查,在组合框中使用字典的所有内容都涉及使用字典作为数据源。我认为这是可能的,因为它在ItemTemplate中工作,我可以使用Attributes[listna
public class Entity
{
public Guid ID;
public Dictionary<String, object> Attributes;
}
我想在组合框中显示键为listname
的属性值作为DataTextField,但我不知道如何执行此操作。我已经在这里进行了检查,在组合框中使用字典的所有内容都涉及使用字典作为数据源。我认为这是可能的,因为它在ItemTemplate中工作,我可以使用Attributes[listname]
使它在DataField属性的RadGrid中工作,但当我尝试该构造时,它不起作用
我怎样才能让它工作 当你说“我尝试那个构造,它不工作”,它怎么不工作?它是否抛出任何错误,或者只是显示空白/错误的数据?它表示它无法在该实体上找到属性[listname],或者沿着这些行的其他内容。但我在调试过程中检查了对象,它就在那里。我只需要弄清楚如何访问它。我试过使用单引号、转义双引号和无引号。他们都失败了。我尝试使用Eval(Attributes[listname]),它试图获得一个名为Attributes的类。
<telerik:RadComboBox runat="server" ID="CboLists" DataValueField="Id">
<ItemTemplate>
<table>
<tr>
<td>
<b><%# DataBinder.Eval(Container.DataItem, "Attributes['listname']") %></b> (<%# ViewHelper.GetBooleanValue("list", "type",(bool)((Entity)Container.DataItem).Attributes["type"]) %>)
</td>
</tr>
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem, "Attributes['membercount']") %> Leden
</td>
</tr>
</table>
</ItemTemplate>
</telerik:RadComboBox>