Introduction

In this How To we shall demonstrate some ways in which the Link Collection property can be used. It is possible to save a collection of links on a page. This is a useful feature, for example, if you want to create a lists of links to related pages.

Add the Link Collection property

Add the Link Collection property type to a page type:

In edit mode Add the links:

Control Link Collection rendering

You can use the EPiServer Property control to render the LinkCollection (the Property control will render the items as an unordered list):

CopyC#
<EPiServer:Property ID="Property1" runat="server" PropertyName="RelatedLinks" CssClass="MyLinks" />

Alternatively, display the links with the ASP.NET repeater control to render the items (can be utilized to have more control over rendering):

CopyC#
<asp:Repeater runat="server" ID="linkRepeater">
 <HeaderTemplate><h2>Links</h2></HeaderTemplate>
 <ItemTemplate>
      <a href='<%# (Container.DataItem as LinkItem).Href %>' 
            target='<%# (Container.DataItem as LinkItem).Target %>' title='<%# (Container.DataItem as LinkItem).Title %>'>
                          <%# (Container.DataItem as LinkItem).Text %> <br />
      </a>
 </ItemTemplate>                
</asp:Repeater>
One way to get the links from the CurrentPage in Code behind:
CopyC#
if (!IsPostBack)
{
    if (CurrentPage["RelatedLinks"] != null)
    {
        LinkItemCollection links = CurrentPage.Property["RelatedLinks"].Value as LinkItemCollection;
        linkRepeater.DataSource = links;
        linkRepeater.DataBind();
    }
}