Try our conversational search powered by Generative AI!

Repeat a repeater

Vote:
 

Hi!

I have a Page Template (1) with this code:

<h2><EPiServer:Property runat="server" PropertyName="PageName" /></h2>
            <div class="bread"><EPiServer:Property runat="server" PropertyName="Pufftext" /></div>
            <div class="links">
                <asp:Repeater runat="server" ID="ItemRepeater">
                    <ItemTemplate>
                        <a href='<%# (Container.DataItem as EPiServer.SpecializedProperties.LinkItem).GetMappedHref() %>' 
                        rel='lightbox[<%# (Container.DataItem as EPiServer.SpecializedProperties.LinkItem).Text %>]' 
                        title='<%# (Container.DataItem as EPiServer.SpecializedProperties.LinkItem).Title %>'
                        class='<%# Container.ItemIndex == 0 ? "arrow" : "noClass" %>' >
                        <%# Container.ItemIndex == 0 ? "Visa bilder" : "" %>
                        </a>
                    </ItemTemplate>                
                </asp:Repeater>

Code behind:

LinkItemCollection links = CurrentPage.Property["ImageGallaryControl"].Value as LinkItemCollection;
                    ItemRepeater.DataSource = links;
                    ItemRepeater.DataBind();

        

Following this guide: http://sdk.episerver.com/library/cms5/Developers%20Guide/How%20To/Use%20Link%20Collection%20property.htm

It works great.

 

However, this PageTemplate should be used for child pages. A parent page should then have repeater for these children. Like this Page Template (2):

<EPiServer:PageList ID="VaraFavoriterRepeater" PageLinkProperty="PageLink" runat="server">
                            <ItemTemplate>
                                <div class="vf">
                                    <div class="c1">
                                        <div class="rc-250-top"></div>
                                        <div class="pic"><img src='<%# Container.CurrentPage["Puffbild"] %>' alt='' /></div>
                                        <div class="rc-250-bot"></div>
                                    </div>
                                    <div class="c2">
                                        <h2><EPiServer:Property runat="server" PropertyName="PageName" /></h2>
                                        <div class="bread"><EPiServer:Property runat="server" PropertyName="Pufftext" /></div>
                                        <div class="links">
                                            <asp:Repeater runat="server" ID="ItemRepeater">
                                                <ItemTemplate>
                                                    <a href='<%# (Container.DataItem as EPiServer.SpecializedProperties.LinkItem).GetMappedHref() %>' 
                                                    rel='lightbox[<%# (Container.DataItem as EPiServer.SpecializedProperties.LinkItem).Text %>]' 
                                                    title='<%# (Container.DataItem as EPiServer.SpecializedProperties.LinkItem).Title %>'
                                                    class='<%# Container.ItemIndex == 0 ? "arrow" : "noClass" %>' >
                                                    <%# Container.ItemIndex == 0 ? "Visa bilder" : ""%>
                                                    </a>
                                                </ItemTemplate>                
                                            </asp:Repeater>
                                            <asp:PlaceHolder runat="server" Visible='<%# Container.CurrentPage["MapLink"] != null%>'>
                                                <a href='<%# Container.CurrentPage ["MapLink"] %>' rel='lightbox[<%# Container.CurrentPage ["MapNr"] %>]' title="Visa på kartan" class="arrow right">Visa på kartan</a>
                                            </asp:PlaceHolder>
                                            <div class="cc"></div>
                                        </div>
                                    </div>
                                <div class="cc"></div>
                                </div>
                            </ItemTemplate>
                        </EPiServer:PageList>



The problem is that I cant get to list the things in the repeater of the children. How do I do that?

Thanks


 

#62718
Nov 01, 2012 14:51
Vote:
 

The code ... =/

#62719
Nov 01, 2012 14:51
Vote:
 

The code is terrible cluttered. Look, what I want to do is use a repeater inside a EpiServer:PageList but I cant get it to work.

#62726
Edited, Nov 01, 2012 15:26
Vote:
 

Think I solved it with DataSource='<%#Container.CurrentPage["ImageGallaryControl"]%>' on the repeater =)

#62727
Nov 01, 2012 15:31
Vote:
 

Yes it is definitely possible to nest repeaters or pagelists but as you noticed you have to set the datasource of the nested repeater in one way or the other (in markup as you did is the simplest way as long as it's sufficient and you don't need to do more advanced operations to set the data source.

#62729
Nov 01, 2012 15:34
Vote:
 

Thank you Magnus, it will do for now. Have a nice day. =)

#62730
Nov 01, 2012 15:35
Vote:
 

But how do I disable the fallback language for the PageList?

#62759
Nov 02, 2012 11:03
Vote:
 

If you want to manipulate the colleciton of pages in other ways than what the built in filter proerties allow you to do (RequiredAccess, PublishStatus etc) there are several ways. The simplest in this case is probably to use the code behind to get your root node (read the property you would otherwise set in PageListProperty), load its child pages using the language selector you want and set the DataSource property of the PageList.

#62764
Nov 02, 2012 11:14
Vote:
 

Iam not quite following you. =)

In the front end code, the PageList should not have a PageLinkProperty then, correct? That is removed.

In the code behind I should type something like:

VaraFavoriterRepeater.DataSource = CurrentPage.PageLink.???

// VaraFavoriterRepeater is the PageList (just to confuse things ;))

#62765
Nov 02, 2012 11:27
Vote:
 

First, use the property to get the root page, then compile the list of pages in a way that is appropriate for your requirements. If you would use PageLinkProperty="RootLink" in codefront, in codebehind you could do this:

PageLink rootLink = CurrentPage["RootLink"] as PageReference;
if (rootLink != null)
{
    VaraFavoriterRepeater.DataSource = DataFactory.Instance.GetChildren(rootLink, new LanguageSelector(CurrentPage.LanguageBranch));
}

I haven't tried this so I'm not sure the language selection is correct or does what you want it to do, but basically you could do whatever you wanted with the collection returned by GetChildren before setting it to the datasource property of the PageList, so you could manually remove the pages you don't want in there if all else fails.

#62766
Edited, Nov 02, 2012 11:36
Vote:
 

// Front end. PageLinkProperty is set to PageLink, so the children of that page is repeated.
EPiServer:PageList ID="VaraFavoriterRepeater" PageLinkProperty="PageLink"

// Back end. There is no type PageLink? You write a variable named rootLink that is of type PageLink, is that correct? In the Page_Load event?

#62782
Nov 02, 2012 12:39
Vote:
 
#62783
Edited, Nov 02, 2012 12:39
Vote:
 

This makes rootLink a pagereference: var rootLink = CurrentPage.PageLink as PageReference; I try from there

#62784
Nov 02, 2012 12:43
Vote:
 

It worked =))

- No PageLinkProperty in code front because that seams to override it and all is displayed.

- In code behind:

 

var rootLink = CurrentPage.PageLink as PageReference;
if (rootLink != null)
{
VaraFavoriterRepeater.DataSource = DataFactory.Instance.GetChildren(rootLink, new LanguageSelector(CurrentPage.LanguageBranch));
}

 

#62786
Nov 02, 2012 12:50
Vote:
 

You don't need to cast CurrentPage.PageLink to a PageReference, it already is. I assumed you had a property where you pointed to the page you wanted to list the children of. If you want to use the current page you can skip a lot of code and just use the below since you don't even need the null check:

VaraFavoriterRepeater.DataSource = DataFactory.Instance.GetChildren(CurrentPage.PageLink, new LanguageSelector(CurrentPage.LanguageBranch));

#62788
Nov 02, 2012 13:17
Vote:
 

Yes, reviewing the code I figured that out. All's well. Have a nice weekend Magnus! Thanks big time

#62789
Nov 02, 2012 13:33
Vote:
 

One other thing ... To give the best service to our editors, I want the PageLink to appear here
rel='lightbox[<%# (Container.DataItem as EPiServer.SpecializedProperties.LinkItem).Text %>]'

This is the nested repeater on the parent page. As you remember I set the datasource to the Container.CurrentPage["ImageGallaryControl"]% so Container.CurrentPage.PageLink doesnt work. Anyway to fix it?

Another thing by the way CurrentPage.PageLink in inline code gives the page id? Correct? Why is that? It doesnt mather for my solution (hard to explain), but Iam just courius.

#62940
Nov 05, 2012 16:32
Vote:
 

The inline syntax always outputs strings (unless it is data binding syntax in a server attribute) which is why you see the ID, it is simply the ToString representation of the PageReference.

The reason you can't use Container.CurrentPage.PageLink in the repater is twofold: First, the Container.CurrentPage property is unique to the EPiServer controls, the standard controls like repater have no knowledge of PageDatas and other EPiServer objects. Second, since you use a LinkCollection as source there wouldn't even be an unambiguous PageData since a LinkCollection can point to other things than pages.

If the links in the linkcollection are pages you can get the corresponding PageData. You can find inspiration of how here:

http://joelabrahamsson.com/entry/convert-a-linkitemcollection-to-a-list-of-pagedata

I suggest you implement a method in the codebehind which takes the LinkItem as input and outputs the ID as a string or whatever you wanted in the rel-attribute. In that method you can handle the case when the LinkItem points to something else than a PageData.

#62956
Nov 06, 2012 9:02
Vote:
 

Ok thanks I look in to it.

#62957
Nov 06, 2012 9:35
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.