The content tree is as follows:
content
-News Listing
-Article1
-Article2
-Article3
Each of the Articles is of a Data Template - "News Article" which is as:
News Article
Article --(Field section)
Related Articles --(Multilist - with datasource as '/content/News Listing')
Each article has the other 2 articles as its 'Related Articles'. For eg: Article1 has related articles 2&3 and so on.
Markup:
<h3>Related articles</h3>
<asp:Repeater ID="rpArticles" runat="server" ItemType="Sitecore.Data.Items.Item">
<HeaderTemplate>
<ul class="relatedArticles">
</HeaderTemplate>
<ItemTemplate>
<li>
<sc:Link Field="<%#Item.Paths.FullPath %>" runat="server" Item="<%#Container.DataItem %>">
<sc:Text Field="Heading" runat="server"/>
</sc:Link>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
Code:
private void Page_Load(object sender, EventArgs e)
{
MultilistField relatedArticles = Sitecore.Context.Item.Fields["Related Articles"];
rpArticles.DataSource = relatedArticles.TargetIDs.Select(id => Sitecore.Context.Database.GetItem(id));
rpArticles.DataBind();
}
The above markup is a solution from Here
'Heading' is the name of the field (eg: Article1, Article2 etc..)
When I browse 'News Article 1', the related articles should be 2 & 3, but the output is incorrect & also no anchor tags. Just plain text.
What is wrong in my code.
output:
Related Articles
Article1
Article1