[英]ASP.NET Strongly-typed DataControl (Repeater) with complex ItemType failing
I've got a structure of three nested repeaters to render out a tabs and then under those tabs a number of items grouped by headings. 我有一个由三个嵌套的中继器组成的结构,以呈现一个选项卡,然后在这些选项卡下按标题将许多项目分组。 I've been using the strongly-typed data controls in .NET 4.5 successfully on standard
IEnumerable
types but this is my first time with a Dictionary<T1,T2>
. 我一直在.NET 4.5中成功在标准
IEnumerable
类型上使用强类型数据控件,但这是我第一次使用Dictionary<T1,T2>
。 Nonetheless I've seen another Stackoverflow question use a Dictionary
as the DataSource
successfully by declaring the ItemType
as KeyValuePair<T1, T2>
. 尽管如此,我已经看到另一个Stackoverflow问题,通过将
ItemType
声明为KeyValuePair<T1, T2>
成功地将Dictionary
用作DataSource
。
Markup: 标记:
<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>
Codebehind: 代码背后:
var myDatasource = new Dictionary<string, Dictionary<string, List<Item>>>();
// add some items
rptTabs.DataSource = myDatasource;
rptTabs.DataBind();
Here's the Exception/Stack trace I'm getting: 这是我得到的异常/堆栈跟踪:
Appears as if the page can't be built because it can't resolve the ItemType by string
name. 似乎无法建立页面,因为它无法通过
string
名称解析ItemType。 The thing is, I get intellisense on my <%# Item.Key #%>
so the intellisense engine can resolve the type by string name but the runtime can't? 问题是,我在
<%# Item.Key #%>
上获取了智能感知功能,因此智能感知引擎可以通过字符串名称解析类型,但是运行时无法?
Note: I doubt it's the Sitecore.Data.Items.Item
type failing as I've used it before inside an IEnumerable meaning the ItemType was Sitecore.Data.Items.Item
. 注意:我怀疑是
Sitecore.Data.Items.Item
类型失败,因为我在IEnumerable之前使用过它,这意味着ItemType是Sitecore.Data.Items.Item
。
Any help would be appreciated! 任何帮助,将不胜感激!
From what I've seen the ItemType property does not like the <
angle brackets >
. 从我所看到的来看,ItemType属性不喜欢
<
尖括号>
。 The answers I have read have shown that replacing all the angle brackets with their respective square brackets seems to work. 我已阅读的答案表明,将所有尖括号替换为它们各自的方括号似乎有效。
Replace the following: 替换以下内容:
<
with [
<
与[
>
with ]
>
与]
So you get: 这样就得到:
ItemType="System.Collections.Generic.KeyValuePair[System.String, System.Collections.Generic.Dictionary[System.String, System.Collections.Generic.List[Sitecore.Data.Items.Item]]]
I was running into a simliar error. 我遇到了类似的错误。 However, in my case I found that I was trying to access the
<%# Item.Property %>
from within the HeaderTemplate
. 但是,就我而言,我发现我试图从
HeaderTemplate
内访问<%# Item.Property %>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.