you, you need to use PageTypeBuilder to do this from my experience
(Article)PageTypeBuilder.PageTypeResolver.Instance.ConvertToTyped((PageData)Container.DataItem)
Do all the pagetypes inherit from typed page data. or is container.DataItem null. that could be an issue since it can't cast to type Pagedata
Yes, they do inherit from Pagedata, through base classes.
The DataItem should not be null. It all worked before the upgrade to R2
<EPiServer:PageList runat="server" ID="ConnectedArticles">
<ItemTemplate>
<div class="post">
<div class="heading">
<h3>
<EPiServer:Property ID="Property3" runat="server" PropertyName="PageLink" />
</h3>
</div>
<p class="timestamp"><%# ReturnPublishDate((EPiServer.Core.PageData)Container.DataItem)%> |
<%# GetCategoryName((EPiServer.Core.PageData)Container.DataItem)%></p>
<div class="mainBody ingress">
<p><%# ReturnIngress((Article)PageTypeBuilder.PageTypeResolver.Instance.ConvertToTyped((EPiServer.Core.PageData)Container.DataItem))%></p>
</div>
</div>
</ItemTemplate>
</EPiServer:PageList>
Actually this PageList works - no errors, but it would be better using a method converting to correct page type or using code behind instead of the page(view).
Weird, i have used this on all my 6r2 projects and it works. Is it something maybe that isn't of type article. I haven't ran into that issue.
I wrote an extension method for passing in data item and returns the type instead of that long chain of code. data.Get<Article>() returns article page.
Yepp, got some help from Joel Abrahamson and trying out with the AsTyped extension.
.AsTyped() when getting a PageCollection solved it.
PageDataCollection pdc = DataFactory.Instance.FindPagesWithCriteria(pageLink, criterias).AsTyped();
Thank you for your help, Joshua,
After upgrading to R2 I'm getting errors in PageList when casting from PageBase to custom PageType (created with PageTypeBuilder).