Home/ASP.NET Forums/General ASP.NET/Data Scaffolding using ASP.NET Dynamic Data/How to Sort my objects in Dynamic Data?

How to Sort my objects in Dynamic Data? [Answered]RSS

16 replies

Last post Nov 30, 2009 07:51 PM by CrowSol

~ Remember To Mark The Post(s) That Helped You As The ANSWER ~
Shakti Singh Tanwar
.Net Trainer (MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])
  • sjnaughton

    sjnaughton

    All-Star

    28438 Points

    5741 Posts

    MVP

    Re: How to Sort my objects in Dynamic Data?

    Aug 29, 2009 11:48 AM|sjnaughton|LINK

     Hi Dynamic2008, I don't think that is possible with DD v1 you could do it with a custom filter in DD Preview 4, the only sort ability come from the DisplayColumn attribute like [DisplayColumn("DisplayColumnName","SortColumnName", false)] the final property set the sort to decending if set to true. So for DD v1 you can only set a single column to be sorted on.

    Dynamic Data

    See my blog C# Bits | Twitter @sjnaughton
    Always seeking an elegant solution.
  • Dynamic2008

    Dynamic2008

    Member

    127 Points

    164 Posts

    Re: How to Sort my objects in Dynamic Data?

    Aug 29, 2009 05:01 PM|Dynamic2008|LINK

    Ah, that's bad to hear.

    Why ASP.NET dynamic data simply doesn't generate application layers (e.g. Data Access, Business Logic and UI) so that they can be used seperately. What are the requirements for DD Preview 4? .NET 4.0?

    If it needs .NET 4.0 I won't be able to use it.

    Do you know of any other good data entry solution?

    I think maybe best is to create an application myself which simply generates the layers for me, etc.

    I have heard of TierDeveloper which is free; I may try that before developing an app myself.

    Seek and you will find!
  • Shakti Singh Tanwar

    Shakti Singh...

    Star

    10892 Points

    1828 Posts

    Re: How to Sort my objects in Dynamic Data?

    Aug 29, 2009 05:59 PM|Shakti Singh Tanwar|LINK

     Have you tried my solution?

    ~ Remember To Mark The Post(s) That Helped You As The ANSWER ~
    Shakti Singh Tanwar
    .Net Trainer (MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])
  • Dynamic2008

    Dynamic2008

    Member

    127 Points

    164 Posts

    Re: How to Sort my objects in Dynamic Data?

    Aug 29, 2009 07:14 PM|Dynamic2008|LINK

    Shakti,

    I believe that's not a solution.

    That linq statement returns only one row anyway, so there i no point in ordering that.

    Instead of First() maybe I should have written Single() to be more clear.

    Thanks,

    Seek and you will find!
  • sjnaughton

    sjnaughton

    All-Star

    28438 Points

    5741 Posts

    MVP

    Re: How to Sort my objects in Dynamic Data?

    Aug 29, 2009 11:13 PM|sjnaughton|LINK

    Dynamic2008

    Why ASP.NET dynamic data simply doesn't generate application layers (e.g. Data Access, Business Logic and UI) so that they can be used seperately. What are the requirements for DD Preview 4? .NET 4.0?

    If it needs .NET 4.0 I won't be able to use it.

    You need the 99.0.0.0 assemblies that come in the common files folder [:(] you could always use the bits from the old Futures project which had all the source code and use the filter repeater and just written custom filters see: Dynamic Data Futures VS2008 SP1 RTM it this does not have the full source anylonger I have a copy [;)]

    Dynamic Data filters

    See my blog C# Bits | Twitter @sjnaughton
    Always seeking an elegant solution.
  • Dynamic2008

    Dynamic2008

    Member

    127 Points

    164 Posts

    Re: How to Sort my objects in Dynamic Data?

    Aug 30, 2009 06:25 AM|Dynamic2008|LINK

    Thanks I will look into that.

    A potential solution: just an idea cam to me when I was asleep that if second parameter (SortColumn) of DisplayColumn attribute needs an existing property to be able to sort the results what I might be able to do is to add a new property to my class such as "ReportRoleDisplay" and put the logic I wrote for ToString() inside its get{} statement. Then I will set the SortColumn to be the name of the new property. It may work!

    I will try that on Tuesday; now enjoying my last summer bank holiday ;)




    Seek and you will find!
  • sjnaughton

    sjnaughton

    All-Star

    28438 Points

    5741 Posts

    MVP

    Re: How to Sort my objects in Dynamic Data?

    Aug 30, 2009 10:55 AM|sjnaughton|LINK

     Good Idea I did something like this in a recent project we created a calculated column that just concatenated the two columns we wanted to sort on and used them as the display column. [:D]

    Dynamic Data Calculated Column Sort Column

    See my blog C# Bits | Twitter @sjnaughton
    Always seeking an elegant solution.
  • sjnaughton

    sjnaughton

    All-Star

    28438 Points

    5741 Posts

    MVP

    Re: How to Sort my objects in Dynamic Data?

    Aug 31, 2009 09:37 AM|sjnaughton|LINK

    Dynamic2008

    I might be able to do is to add a new property to my class such as "ReportRoleDisplay" and put the logic I wrote for ToString() inside its get{} statement. Then I will set the SortColumn to be the name of the new property. It may work!
     

    It wont work as the property does not exist in the DB [:(]

    Dynamic Data Sort Filters

    See my blog C# Bits | Twitter @sjnaughton
    Always seeking an elegant solution.
  • Dynamic2008

    Dynamic2008

    Member

    127 Points

    164 Posts

    Re: How to Sort my objects in Dynamic Data?

    Sep 01, 2009 08:38 AM|Dynamic2008|LINK

    How did you create the calculated column when DisplayColumn attribute only accepts database table columns (non-calculated)?

    Seek and you will find!
  • sjnaughton

    sjnaughton

    All-Star

    28438 Points

    5741 Posts

    MVP

    Re: How to Sort my objects in Dynamic Data?

    Sep 01, 2009 11:12 AM|sjnaughton|LINK

     In the databaseI added a new column called FullName and in the "Computed Column Specification" Formula Filed I added the formula [FirstName]+', '+[LastName] this gives me a field in the DB  (Where you need it to filter) that I can filter on and use to display in Drop down lists using DisplayColumn attribute.

    Dynamic Data Computed Column

    See my blog C# Bits | Twitter @sjnaughton
    Always seeking an elegant solution.
  • Dynamic2008

    Dynamic2008

    Member

    127 Points

    164 Posts

    Re: How to Sort my objects in Dynamic Data?

    Sep 02, 2009 08:37 AM|Dynamic2008|LINK

    That is a solution I agree but an ugly one, isn't it?!

    I was thinking maybe we can create a new CustomDisplayColumn attribute which inherits from DisplayColumn, then to overwrite the functionality where it's doing it's sorting job to sort based on the EF class property rather than a table column. Or having both functionalities I mean for instance extending CustomDisplay Column to have 2 properties called "SortByProperty" and "SortByColumn".

    Have you thought about this?

    Seek and you will find!
  • sjnaughton

    sjnaughton

    All-Star

    28438 Points

    5741 Posts

    MVP

    Re: How to Sort my objects in Dynamic Data?

    Sep 02, 2009 10:30 AM|sjnaughton|LINK

     

    Dynamic2008

    I was thinking maybe we can create a new CustomDisplayColumn attribute which inherits from DisplayColumn, then to overwrite the functionality where it's doing it's sorting job to sort based on the EF class property rather than a table column. Or having both functionalities I mean for instance extending CustomDisplay Column to have 2 properties called "SortByProperty" and "SortByColumn".

    This will be  a good solution when you could use with Preview 4 and the new filtering system as the attribute does non of the work it's self but it is consumed else where filters etc.

    You however create your ownAttribute and your own Filter that does the getting an sorting of the based on a number of columns with either V1 or Preview 4

    Dynamic Data

    See my blog C# Bits | Twitter @sjnaughton
    Always seeking an elegant solution.
  • Dynamic2008

    Dynamic2008

    Member

    127 Points

    164 Posts

    Re: How to Sort my objects in Dynamic Data?

    Sep 03, 2009 09:30 AM|Dynamic2008|LINK

    I read from here that prerequisites for Dynamic Data Preview 4.0 are Visual Studio 2008 and .NET Framework 3.5 SP1, so apparently I don't have to have .NET 4.0 installed :)

    So how do you resolve this issue in preview 4.0?



    Seek and you will find!
  • sjnaughton

    sjnaughton

    All-Star

    28438 Points

    5741 Posts

    MVP

    Re: How to Sort my objects in Dynamic Data?

    Sep 03, 2009 11:53 AM|sjnaughton|LINK

     No you don't but thae final version of DD v2 will be .Net 4.0 and if you look at the dll's they are ver 99.0.0.0 you can use it but there may be breaking changes before the RTM.

    Dynamic Data

    See my blog C# Bits | Twitter @sjnaughton
    Always seeking an elegant solution.
  • CrowSol

    CrowSol

    Member

    196 Points

    100 Posts

    Re: How to Sort my objects in Dynamic Data?

    Nov 30, 2009 07:51 PM|CrowSol|LINK

    Here is a solution that allows you to sort a GridView with Visual Studio 2008 sp1.   

     

    protected void Page_Init(object sender, EventArgs e)
        {
        	//Your other code
    
    
    
    
        	// Sorting
            GridView1.Sort("OrderId", SortDirection.Ascending);
        }


     

    dynamicdata sort

    Dan Crowell
    www.crowsol.com
  • ‹ Previous Thread|Next Thread ›