2013-04-23 20 views
2

我有一个三个嵌套中继器的结构来呈现标签,然后在这些标签下按标题分组。我一直在标准IEnumerable类型中成功使用.NET 4.5中的强类型数据控件,但这是我第一次使用Dictionary<T1,T2>。尽管如此,我已经看到另一Stackoverflow question使用Dictionary作为DataSource成功宣布ItemTypeKeyValuePair<T1, T2>复杂ItemType失败的强类型DataControl(Repeater)

标记:

<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(); 

这里的异常/堆栈跟踪我越来越:Yellow Screen

看起来好像页面无法因为它无法解决string的ItemType问题 名称。问题是,我在我的<%# Item.Key #%>上收到intellisense,因此intellisense引擎可以通过字符串名称解析该类型,但运行时不能?

注:我怀疑这是Sitecore.Data.Items.Item类型失败,因为我之前在IEnumerable中使用它,意味着ItemType是Sitecore.Data.Items.Item

任何帮助,将不胜感激!

+0

我真的不想写'ItemDataBound'处理程序来简单地通过ID找到内部控件并绑定它们的数据源。烦! – benmccallum 2013-04-23 05:33:07

回答

0

从我看到的ItemType属性不喜欢<尖括号>。我读过的答案表明,用各自的方括号代替所有的尖括号似乎是可行的。

替换以下:

  • <[
  • >]

所以,你得到:

ItemType="System.Collections.Generic.KeyValuePair[System.String, System.Collections.Generic.Dictionary[System.String, System.Collections.Generic.List[Sitecore.Data.Items.Item]]] 

我跑成simliar错误。但是,在我的情况下,我发现我试图从HeaderTemplate内访问<%# Item.Property %>

+0

谢谢队友。当我有机会时,我会看看,如果它有效,回来标记为答案。 – benmccallum 2013-05-01 01:28:04

+0

嗯没有工作..现在我尝试访问项目时得到以下内容。 [New Error](http://imgur.com/2I5Yav3) CS0305:使用泛型类型'System.Collections.Generic.KeyValuePair '需要2个类型参数 – benmccallum 2013-06-17 08:00:03