【发布时间】:2013-04-23 05:31:31
【问题描述】:
我有一个由三个嵌套转发器组成的结构来呈现一个选项卡,然后在这些选项卡下,一些按标题分组的项目。我一直在标准IEnumerable 类型上成功使用.NET 4.5 中的强类型数据控件,但这是我第一次使用Dictionary<T1,T2>。尽管如此,我还是看到另一个Stackoverflow question 通过将ItemType 声明为KeyValuePair<T1, T2> 成功地将Dictionary 用作DataSource。
标记:
<asp:Repeater ID="rptTabs" runat="server"
ItemType="System.Collections.Generic.KeyValuePair<System.String, System.Collections.Generic.Dictionary<System.String, System.Collections.Generic.List<Sitecore.Data.Items.Item>>>">
<ItemTemplate>
<%# Item.Key %>
<%-- ... more repeaters under but they are commented out for now as it's the outer on that is failing --%>
</ItemTemplate>
</asp:Repeater>
代码隐藏:
var myDatasource = new Dictionary<string, Dictionary<string, List<Item>>>();
// add some items
rptTabs.DataSource = myDatasource;
rptTabs.DataBind();
这是我得到的异常/堆栈跟踪:
似乎无法构建页面,因为它无法通过 string 名称解析 ItemType。问题是,我在 <%# Item.Key #%> 上获得了智能感知,因此智能感知引擎可以通过字符串名称解析类型,但运行时不能?
注意:我怀疑这是 Sitecore.Data.Items.Item 类型失败,因为我之前在 IEnumerable 中使用过它,这意味着 ItemType 是 Sitecore.Data.Items.Item。
任何帮助将不胜感激!
【问题讨论】:
-
我真的不想编写
ItemDataBound处理程序来简单地通过ID 查找内部控件并绑定它们的数据源。烦人!