Try our conversational search powered by Generative AI!

Page list that includes subpages


I'd like to do a page list that includes subpages. There is sort of a "News" main page and that in itself contains a few sub group categories of news that the actual news are put in. What I'd like to do is to make a page list that summons up the latest, say 10, news from any of these categories.

The code that is being used right has one page list for every category and these page lists are being used by a main page list that uses the sub category ones as datasource. This works but requires that changes are made in the code every time a category is added. I'd like this to be done in a better way but I can't imagine how. Any suggestions? Is there a way to just point a page list to a node and have it include the sub pages aswell?

Aug 18, 2010 7:30

I'm not sure I understand what you are trying to do. Do you want to aggregate the latest x news items from a whole structure or do you want to create a treelike structure but skip a level?

Some general approaches are:

Use the PageTree control which allows you to display pages recursively from a specified root node. You can specifiy the number of levels, add filtering and sorting etc.

Use nested PageList controls (put a PageList in the ItemTemplate of the PageList and use <%#Container.CurrentPage.PageLink%> as the nested PageList's PageLink property). This would allow you to skip the intermediate "Category" level.

Use a SearchDataSource - Repeater combination. The SearchDataSource can be set to search for n items from a root node and it's SortOrder property can be set to sort by publish date. You can refine further by filtering for page type, menu visibility or custom filters.

Aug 18, 2010 8:24

I did my best trying to explain the situation but you sort of got it. I didn't get the methods you suggested to work as I wanted them to so I ended up creating a page list called clipList and went for this in the code behind.

PageList[] pl = new PageList[clipList.DataCount];

int i = 0;

foreach (PageData pd in clipList)
    pl[i] = new PageList();
    pl[i].PageLink = pd.PageLink;

i = 1;

while (i <= clipList.DataCount - 1)
    pl[i].DataSource = pl[i-1];


clipList.DataSource = pl[i];

Aug 19, 2010 11:46

I don't even know what I would expect that to do, it's like a chain of datasources? If I try to interpret things again, can it be said that you want to collect all grandchildren of a page and present the x latest? Here's a way that might work:


in OnInit, attach an event handler to GetChildrenCallback, like so:

clipList.PageLoader.GetChildrenCallback = new HierarchicalPageLoader.GetChildrenMethod(LoadChildren);

then implement the callback to get the grandchildren instead of the children (using Linq, can of course be done by looping instead):

private PageDataCollection LoadChildren(PageReference pageLink)
    var children = DataFactory.Instance.GetChildren(pageLink);
    var grandChildren = children.SelectMany(c => DataFactory.Instance.GetChildren(c.PageLink));
    return new PageDataCollection(grandChildren); 

You can also simply get the grandchildren from the PageReference and set the DataSource property of the pagelist rather than setting the PageLink property and letting it get the pages itself using the callback.

Creating several webcontrols for use in codebehind seems unnecessary unless it accomplishes something I don't get from the source code. But if it works... :)

Aug 19, 2010 12:16

What I wanted to do was collect all news from a few different news categories and present them in one list. The code above did that so I'm just gooing to stick to it and move on. Like you said, "if it works...". :) Thanks for the effort!

Aug 19, 2010 13:14
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.