Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a type Customer as
C#
Class Customer
{
    string Name;
    Address address;
    ...
}

And class Address as
C#
Class Address
{
    string Street;
    int HouseNum;
    ....
}

I am creating a list of Customer as
C#
List<Customer> CustSource= new List<Customer>();

Then I bind CustSource to a repeater.
Repeater have a column named 'Street' bound with `CustSource.address.Street`, 'House Number' bound with `CustSource.address.HouseNum`, 'Name' bound with `CustSource.Name` and so on.
I want to sort the the binding source i.e. CustSource at runtime. I know it could be done as CustSource.OrderBy(x=> x.Name) when I know the member at compile time. TO decide the member to sort on at runtime, I have written an extension method with the help of this article: http://stackoverflow.com/questions/307512/how-do-i-apply-orderby-on-an-iqueryable-using-a-string-column-name-within-a-gene[^]

Problem is, When I sort it on the primitive property of Customer class like 'Name', it works fine, but how can I sort on the `Address.Street` property of CustSource?
Posted
Updated 26-Jul-14 22:56pm
v3
Comments
Andreas Gieriet 26-Jul-14 16:23pm    
Your question is not clear. What exactly is the problem to solve?
You don't know how to add multiple sorting criterions?
You don't know how to provide flexible sorting criterions?
Andi
Sergey Alexandrovich Kryukov 26-Jul-14 16:45pm    
Why adding those words "at runtime"? Do you think it's possible to sort a list at some other time, not during runtime? Which runtime it could be then? Compiler? linker? loader? :-)
—SA
Sky8807 27-Jul-14 4:57am    
With runtime I meant I dont know the name of member to sort on at 'Compile time'. Its decided when user clicks on header of the repeater, which I could not think of a better word to define than 'at runtime' :)

1 solution

If it's about having various collating sequences, you might use the approach as described in Sorting C# collections that have no collating sequence[^].
Cheers
Andi
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900