This project is read-only.

Sorting an n2:ItemDataSource

Nov 18, 2008 at 3:39 PM
I have an n2:ItemDatasource

<n2:ItemDataSource id="idsNews" runat="server" />

How would I go about sorting this in descedning order?

Nov 18, 2008 at 11:10 PM
The ItemDataSource doesn't support sorting (it's a good idea though, and it wouldn't be hard to add).

For the moment I suggest you either make sure your content items are stored as they should be sorted (look in the functional templates news on how to do this) or manually sort and bind the repeater/grid:

var items = newsContainer.GetChildren();
myRepeater.DataSource = items;
May 12, 2009 at 5:35 PM

I found something strange today, my custom version of a news container and news items.. but when a user added a text box to the top of the page, the ItemDataSource also seemed to include that in the repeater display; I thought it would only get the child 'PAGES' rather than the items/parts on that page.. How strange indeed! :(


Tried using the above to get the children, but ended up with nothing showing (which I assume means no items returned to bind). var items = CurrentItem.GetChildren(); myRepeater.datasource = items; myRepeater.databind();


May 13, 2009 at 9:49 AM

I'm a bit concerned with the ItemDataSource problem, I had a look through the source code in ItemDataSource.cs and the way that the ItemDataSource is being called from the aspx page I would expect it would only return the child pages of the item:

    /// List child items of the current item:
    /// <n2:ItemDataSource id="itemSource1" runat="server" />
    /// <asp:Repeater DataSourceID="itemSource1" runat="server">
    ///        <ItemTemplate><p><%# Eval("Title") %></p></ItemTemplate>
    /// </asp:Repeater>

In my code I am using more or less that..

    <n2:ItemDataSource id="IdsFaqs" runat="server" />   
    <asp:Repeater runat="server" ID="RptFaq" DataSourceID="IdsFAQs">
            <script type="text/javascript" src="/_assets/js/ui.core.js"></script>
            <script type="text/javascript" src="/_assets/js/ui.accordion.js"></script>                       
            <script type="text/javascript">
                $(document).ready(function() {                   
            <div id="FAQs">
            <h3><a href="#"><%# Eval("Question") %></a></h3>
                 <%# Eval("Answer") %>             

Cristian (or someone who knows lots) can you clarify if there is a proper way to return simply the child pages rather than all the child items? As if there are droppable zones on pages the items they represent will be returned in the ItemDataSource also? (That what seems to be happening in my example - I added a N2 Textbox to the page, and then get an error about the textbox not having properties that the other item on the page has when the aspx page for the FAQs tries to output).