This is a migrated thread and some comments may be shown as answers.

Sorting in a Nested Repeater

1 Answer 193 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
sitefinitysteve asked on 13 Mar 2010, 06:20 AM
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?

1 Answer, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 16 Mar 2010, 05:42 PM
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.
Tags
LINQ (LINQ specific questions)
Asked by
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Answers by
Damyan Bogoev
Telerik team
Share this question
or