GetRelatedDataByOneHop

Top  Previous  Next

This method returns a DataSet instance containing the topic ID of the page topics found, EPiServer page ID of pages found, and whether the association linking to this page was deleted or published. This data set can easily be bound to the templated data bound controls provided in ASP.NET such as Repeater, DataList and DataGrid.

The DataSet returned by the method contains a single DataTable with the following columns:

Column Name

Description

topicid

The TMCore ID of the page topic found by traversing the association.

pageid

The EPiServer Page ID of the page found by traversing the association.

assocIsPublished

Set to true if the association traversed is published

assocIsDeleted

Set to true if the association traversed is marked as deleted

pageLinkURL (optional)

The URL of the page found by traversing the association.

pageName (optional)

The name of the page found by traversing the association.

The method itself has two forms:

public DataSet GetRelatedDataByOneHop(

 PageData page,

 string assoctype,

 string targroletype

)

and

public DataSet GetRelatedDataByOneHop(

 PageData page,

 string assoctype,

 string targroletype,

 bool addPageLinkAndName

)

 

The page parameter is the EPiServer PageData for the page from which the one-hop traversal will start. This can typically be retrieved from within a Page Template as the CurrentPage value. The assoctype parameter is the subject identifier of the association type to traverse and the targetroletype parameter is the subject identifier of the role type of the role played by the topic at the other end of the traversal. The optional pageLinkURL and pageName columns are included only if the boolean addPageLinkAndName parameter of the second form of method call is set to true. The code snippet below shows a fragment of the code-behind for a Page Template that is using the GetRelatedDataByOneHop method to generate a list of related page links.

DataSet resultsSet = helper.GetRelatedDataByOneHop(

  this.CurrentPage,                                                  // Current page represents a person

  "http://psi.networkedplanet.com/associations/departmenthasmember", // Association type

  "http://psi.networkedplanet.com/roletypes/department",             // Find all the pages playing the role of department

  true);                                                             // Include page link and name

 

if (resultsSet.Tables.Count > 0) {

  // Bind a repeater on the page to the results table

  DepartmentsRepeater.DataSource = resultsSet.Tables[0]; 

  DepartmentsRepeater.DataBind();

}

And in the page template ASPX the repeater code might look like this:

<asp:Repeater runat="server" ID="DepartmentsRepeater">

  <HeaderTemplate><ul></HeaderTemplate>

  <FooterTemplate></ul></FooterTemplate>

  <ItemTemplate>

    <li>

      <a href="<%# DataBinder.Eval(Container.DataItem, "pageLinkURL") %>">

        <%# DataBinder.Eval(Container.DataItem, "pageName") %>

      </a>

    </li>

  </ItemTemplate>

</asp:Repeater>