2013-04-23 48 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