Sorting in a Nested Repeater

2 posts, 0 answers
  1. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 13 Mar 2010 Link to this post

    I bound a nested repeater to a collection inside my dataset (by just using an Eval on the DataSource property in the markup)

    Now I have an index column to sort these results by, but how can I get that sorting to take effect in this "codeless" context.  I mean I could handle ItemDataBound and get\sort the collection myself, but I was hoping to avoid that :)

    I tried returning a sorted list from inside the OA Property itself, but that didnt seem to work
            [Telerik.OpenAccess.FieldAlias("publicationsItem")] 
            public IList<PublicationsItem> PublicationsItems { 
                get {  
                    return (from p in publicationsItem  
                            orderby sortIndex  
                            select p).ToList();  
                } 
            } 


    Is this even doable?
  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 16 Mar 2010 Link to this post

    Hello Steve,

    You should handle the column header click event in order to sort the repeater data:

    <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <table width="100%" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="25%">
                        <%# DataBinder.Eval(Container.DataItem, "EmployeeID") %>
                    </td>
                    <td width="25%">
                        <%# DataBinder.Eval(Container.DataItem, "FirstName") %>
                    </td>
                    <td width="25%">
                        <%# DataBinder.Eval(Container.DataItem, "LastName") %>
                    </td>
                    <td width="25%">
                        <%# DataBinder.Eval(Container.DataItem, "Title") %>
                    </td>
                </tr>
            </table>
        </ItemTemplate>
        <HeaderTemplate>
            <table width="100%" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="25%">
                        <asp:LinkButton ID="lnkEmployeeid" runat="server" OnClick="SortByEmployeeId">EmployeeId</asp:LinkButton>
                    </td>
                    <td width="25%">
                        <asp:LinkButton ID="lnkFirstName" runat="server">FirstName</asp:LinkButton>
                    </td>
                    <td width="25%">
                        <asp:LinkButton ID="lnkLastName" runat="server">LastName</asp:LinkButton>
                    </td>
                    <td width="25%">
                        <asp:LinkButton ID="lnkTitle" runat="server">Title</asp:LinkButton>
                    </td>
                </tr>
            </table>
        </HeaderTemplate>
    </asp:Repeater>

    protected void SortByEmployeeId(object sender, EventArgs e)
    {
        Repeater1.DataSource = context.Employees.OrderBy(emp => emp.EmployeeID);
        Repeater1.DataBind();
    }

    There is no codeless approach to achieve this goal.
    I hope the provided information will be helpful to you.

    Sincerely yours,
    Damyan Bogoev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
Back to Top