ListView in Repeater problem

Vote:
 

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?

#74999
Sep 13, 2013 14:06
Vote:
 

Why a listview? Can't you just use nested repeaters? Outer repeater bound to your pagedatacollection and the nested one to the linkcollection.

#75007
Sep 13, 2013 20:31
Vote:
 

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();
}
}

#75043
Sep 16, 2013 12:57
Vote:
 

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>

 

#75048
Sep 16, 2013 14:21
Vote:
 

Check out this link for a nice post on how to get typed access to your underlying data in your lists:

 

http://www.frederikvig.com/2012/05/strongly-typed-access-to-your-page-data-objects-inside-itemtemplate/

#75049
Sep 16, 2013 14:27
Vote:
 

Thanks Per! Shall give it a try...

#75051
Sep 16, 2013 15:17
Vote:
 

fredrikvig.com seem to be all white at the moment :) shame... 

#75074
Sep 17, 2013 10:02
Vote:
 

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.

 

#75083
Sep 17, 2013 11:30
Vote:
 

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!
    

    

 

#75112
Sep 18, 2013 8:47
Vote:
 

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/

#75116
Sep 18, 2013 10:17
Vote:
 

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...

 

#75120
Sep 18, 2013 11:09
Vote:
 

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

 

 

#75169
Sep 19, 2013 10:41
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.