Why a listview? Can't you just use nested repeaters? Outer repeater bound to your pagedatacollection and the nested one to the linkcollection.
Yes, I guess I could use a repeater instead. I just tried this. Feel a bit unsurtain on how I should point to the correct data source (the child) though... I have the following method which I use together with OnItemDataBound (in first repeater):
protected void ItemBound(object sender, RepeaterItemEventArgs args)
{
currentchild = ?; //
var links = (LinkItemCollection)currentchild.GetPropertyValue<LinkItemCollection>("Files", new LinkItemCollection()); //filer
if (args.Item.ItemType == ListItemType.Item || args.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater childRepeater = (Repeater)args.Item.FindControl("ChildRepeater");
childRepeater.DataSource = links.Distinct(new Comparlink()).ToList(); //...;
childRepeater.DataBind();
}
}
I have used nested repeaters several times and the presentation logic can be pressy slick if you just have the underlying datasource setup.
You could do something link this: Bind the outer repeater to your pagedatacollection. In the itemtemplate of the outer repeater you add your inner one and in the datasource property you send in the pagedata.linkitemcollection which implements ienumerable.
Pseudo code!
<asp:Repeater ID="MainRepeater" runat="server"> //bound to your lpagedatacollection
<ItemTemplate>
<h2><%# typeToList.Heading %></h2>
<asp:Repeater ID="TypesRepeater" runat="server" DataSource="<%#PageDataObject.LinkItemCollectionProperty%>">
<ItemTemplate>
Check out this link for a nice post on how to get typed access to your underlying data in your lists:
See example below: You have to replace ContentType to what you use in your datasource
Something like this:
protected PageData PType { get { return Page.GetDataItem() as PageData; } }
protected LinkItem LItem{ get { return Page.GetDataItem() as LinkItem; } }
In your repeaters on databinding you can access the underlying dataitem in a typed way.
<%#PType.PageName
<%¤LItem.Href
Or whatever you want to display.
Note that you can only do this on databinding so it doesn't work in header and footertemplates.
That sounds like what I'm after! I'm still confused about how I should set the datasource to the child (currentchild). I've managed to get it to work when specifying a specific child like:
protected void ItemBound(object sender, RepeaterItemEventArgs args)
{
currentchild = DataFactory.Instance.GetPage(new PageReference(10824));
var links = (LinkItemCollection)currentchild.GetPropertyValue<LinkItemCollection>("Files", new LinkItemCollection());
if (args.Item.ItemType == ListItemType.Item || args.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater childRepeater = (Repeater)args.Item.FindControl("ChildRepeater");
childRepeater.DataSource = links.Distinct(new Comparlink()).ToList(); //...;
childRepeater.DataBind();
}
}
Thanks for the help!
I did an example in episerver 7 using nested repeaters. If you download that you can see how I set it up.
http://world.episerver.com/Code/Per-Nergard/List-all-page-and-block-types-with-properties/
I'm on CMS 6 and your solution Per seems a bit above my head at the moment... Thanks anyway!
It seems like it would be an "easy" and "common" thing to accomplish but after trying so many different things I start to realize it's not ;) Gah... How difficult should it be to set a property (in this case "Files" - LinkItemCollection) as the datasource for a nested repeater?
I do get the files listed by using <EPiServer:Property runat="server" PropertyName="Files" CssClass="FileLinks" /> but I would like to style the list in a different way... and therefor I need the repeater (or listview). If I can't find an understandable way to do this I guess I just have to let it be for the moment...
I managed to find a solution to my problem... It was pretty simple even though it took me some time to figure out :) Here it is - incase anyone else is interested (in my solution):
In the nested repeater/listview set the datasource by a method (sending the propertyname and pagedata)
<asp:ListView runat="server" ID="Linklisting" ItemPlaceholderID="ItemPlaceHolder" DataSource='<%# setLinkSource("Files", (EPiServer.Core.PageData)Container.DataItem) %>'>
Then method returns the linkitemcollection:
public LinkItemCollection setLinkSource(string prop, PageData page)
{
var links = page.GetPropertyValue<LinkItemCollection>(prop, new LinkItemCollection());
return links;
}
You then have access to the properties by using regular Container.DataItem
Hi!
I'm using a repeater to list a bunch of child pages. Every child page can contain a list of files (stored with LinkCollection property). I'm thinking I should use a ListView nested in the repeater to display the list of files (for the child). I have a hard time getting it to work... Anyone with a good ideá on how to get this to work?