2

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>. Nonetheless I've seen another Stackoverflow question use a Dictionary as the DataSource successfully by declaring the ItemType as KeyValuePair<T1, T2>.

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: Yellow Screen

Appears as if the page can't be built because it can't resolve the ItemType by string name. 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?

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.

Any help would be appreciated!

Community
  • 1
  • 1
benmccallum
  • 1,241
  • 12
  • 27
  • I really don't want to write `ItemDataBound` handlers to simply find the inner controls by ID and bind their datasource. Annoying! – benmccallum Apr 23 '13 at 05:33

1 Answers1

0

From what I've seen the ItemType property does not like the < angle brackets >. 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.

jeremysawesome
  • 7,033
  • 5
  • 33
  • 37
  • Thanks mate. I'll have a look when I get a chance and come back to mark as the answer if it works. – benmccallum May 01 '13 at 01:28
  • Hmm didn't work.. now I get the following when try to access Item. [New Error](http://imgur.com/2I5Yav3) CS0305: Using the generic type 'System.Collections.Generic.KeyValuePair' requires 2 type arguments – benmccallum Jun 17 '13 at 08:00