简体   繁体   中英

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> . 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: 黄屏

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!

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM