Search code examples
c#arraysepiserver

How to add looped items from ItemTemplate into array


I have a PageList with some data, and I want to add all Date's to an array as strings. Seems easy enough but I'm kinda new to this, so anyone out there who knows how to solve this?

<EPiServer:PageList ID="PageList1" runat="server" PageLinkProperty="Root">
    <ItemTemplate>
        <h2><EPiServer:Property runat="server" PropertyName="Title" /></h2>
        <EPiServer:Property runat="server" PropertyName="Date" /><br />
        <EPiServer:Property runat="server" PropertyName="Content" />
        <hr />
    </ItemTemplate>
</EPiServer:PageList>

Solution

  • This is code that will work with any EPi verson. I know you wrote Dates as strings but I made a List of DateTimes instead.

    var reference = (PageReference)CurrentPage["Root"];
    var children = DataFactory.Instance.GetChildren(reference);
    var list = new List<DateTime>();
    
    foreach (PageData pd in children)
    {
        list.Add((DateTime)pd["Date"]);
    }