How to Sort my objects in Dynamic Data?http://forums.asp.net/t/1464517.aspx/1?How+to+Sort+my+objects+in+Dynamic+Data+Mon, 30 Nov 2009 19:51:03 -050014645173375182http://forums.asp.net/p/1464517/3375182.aspx/1?How+to+Sort+my+objects+in+Dynamic+Data+How to Sort my objects in Dynamic Data? <p><br> </p> <p>I am using Entity Framework with ASP.NET Dynamic Data 3.5. I have a ReportRole class which has been extended as following:</p> <p></p> <pre class="prettyprint">[DisplayColumn(&quot;ReportRoleId&quot;)] [MetadataType(typeof(ReportRole_MD))] [DisplayName(&quot;Report Role&quot;)] public partial class ReportRole { public override string ToString() { var result = String.Empty; using (var context = new MIPortalEntities()) { result = (from rr in context.ReportRole where rr.ReportRoleId == this.ReportRoleId let textToDisplay = rr.Report.ReportName &#43; &quot;--&quot; &#43; rr.Role.RoleName select textToDisplay).First(); } return result; } } public class ReportRole_MD { [UIHint(&quot;ReadOnlyText&quot;)] public object ReportRoleId { get; set; } [UIHint(&quot;ReadOnlyText&quot;)] public object UpdatedDate { get; set; } public object Report { get; set; } public object Role { get; set; } }</pre> <p><br> </p> <p>The display text for each report role would be like &quot;ReportName -- RoleName&quot;.</p> <p>By default the ReportRoles are sorted by ReportRoleId, so how can I say the ReportRoles should be sorted based on the value which is returned from ToString() method?</p> <p>Thanks,</p> <p></p> 2009-08-28T15:23:23-04:003375443http://forums.asp.net/p/1464517/3375443.aspx/1?Re+How+to+Sort+my+objects+in+Dynamic+Data+Re: How to Sort my objects in Dynamic Data? <p>&nbsp;try using orderby as</p> <p>&nbsp;<span>using</span><span>&nbsp;(var&nbsp;context&nbsp;=&nbsp;</span><span>new</span><span>&nbsp;MIPortalEntities()) &nbsp;&nbsp;</span> </p> <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;</span> </li><li><span>&nbsp;&nbsp;</span> </li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result&nbsp;=&nbsp;(from&nbsp;rr&nbsp;</span><span>in</span><span>&nbsp;context.ReportRole &nbsp;&nbsp;</span><span></span> </li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;where&nbsp;rr.ReportRoleId&nbsp;==&nbsp;</span><span>this</span><span>.ReportRoleId &nbsp;&nbsp;</span><span></span> </li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let&nbsp;textToDisplay&nbsp;=&nbsp;rr.Report.ReportName&nbsp;&#43;&nbsp;</span><span>&quot;--&quot;</span><span>&nbsp;&#43;&nbsp;rr.Role.RoleName &nbsp;&nbsp;</span><span></span> </li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; orderby&nbsp;&nbsp;rr.ReportRoleId select&nbsp;textToDisplay).First(); &nbsp;&nbsp;</span> </li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li>2009-08-28T17:25:50-04:003376359http://forums.asp.net/p/1464517/3376359.aspx/1?Re+How+to+Sort+my+objects+in+Dynamic+Data+Re: How to Sort my objects in Dynamic Data? <p>&nbsp;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(&quot;DisplayColumnName&quot;,&quot;SortColumnName&quot;, 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.</p> 2009-08-29T11:48:08-04:003376654http://forums.asp.net/p/1464517/3376654.aspx/1?Re+How+to+Sort+my+objects+in+Dynamic+Data+Re: How to Sort my objects in Dynamic Data? <p>Ah, that's bad to hear.</p> <p>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?</p> <p>If it needs .NET 4.0 I won't be able to use it.</p> <p>Do you know of any other good data entry solution?</p> <p>I think maybe best is to create an application myself which simply generates the layers for me, etc.</p> <p>I have heard of&nbsp;TierDeveloper which is free; I may try that before developing an app myself.</p> 2009-08-29T17:01:09-04:003376684http://forums.asp.net/p/1464517/3376684.aspx/1?Re+How+to+Sort+my+objects+in+Dynamic+Data+Re: How to Sort my objects in Dynamic Data? <p>&nbsp;Have you tried my solution?</p> 2009-08-29T17:59:56-04:003376763http://forums.asp.net/p/1464517/3376763.aspx/1?Re+How+to+Sort+my+objects+in+Dynamic+Data+Re: How to Sort my objects in Dynamic Data? <p>Shakti,</p> <p>I believe that's not a solution.</p> <p>That linq statement returns only one row anyway, so there i no point in ordering that.</p> <p>Instead of First() maybe I should have written Single() to be more clear.</p> <p>Thanks,</p> 2009-08-29T19:14:53-04:003376896http://forums.asp.net/p/1464517/3376896.aspx/1?Re+How+to+Sort+my+objects+in+Dynamic+Data+Re: How to Sort my objects in Dynamic Data? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Dynamic2008</h4> <p>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?</p> <p>If it needs .NET 4.0 I won't be able to use it.</p> <p></p> </blockquote> <p></p> <p>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: <a id="ctl00_ctl00_MasterContent_Content_ProjectReleasesSidebar_Sidebar_ReleaseTypeRepeater_ctl00_ReleaseRepeater_ctl16_ReleaseLink" title="Dynamic Data Futures VS2008 SP1 RTM" href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=14475"> Dynamic Data Futures VS2008 SP1 RTM</a>&nbsp;it this does not have the full source anylonger I have a copy [;)]</p> 2009-08-29T23:13:42-04:003377039http://forums.asp.net/p/1464517/3377039.aspx/1?Re+How+to+Sort+my+objects+in+Dynamic+Data+Re: How to Sort my objects in Dynamic Data? <p>Thanks I will look into that.</p> <p>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 &quot;ReportRoleDisplay&quot; 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!</p> <p>I will try that on Tuesday; now enjoying my last summer bank holiday ;)</p> <p><br> </p> <p><br> </p> <p><br> </p> 2009-08-30T06:25:21-04:003377207http://forums.asp.net/p/1464517/3377207.aspx/1?Re+How+to+Sort+my+objects+in+Dynamic+Data+Re: How to Sort my objects in Dynamic Data? <p>&nbsp;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]</p> 2009-08-30T10:55:06-04:003378318http://forums.asp.net/p/1464517/3378318.aspx/1?Re+How+to+Sort+my+objects+in+Dynamic+Data+Re: How to Sort my objects in Dynamic Data? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Dynamic2008</h4> I might be able to do is to add a new property to my class such as &quot;ReportRoleDisplay&quot; 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!</blockquote> &nbsp; <p></p> <p>It wont work as the property does not exist in the DB [:(]</p> 2009-08-31T09:37:34-04:003380329http://forums.asp.net/p/1464517/3380329.aspx/1?Re+How+to+Sort+my+objects+in+Dynamic+Data+Re: How to Sort my objects in Dynamic Data? <p>How did you create the calculated column when DisplayColumn attribute only accepts database table columns (non-calculated)?</p> 2009-09-01T08:38:11-04:003380620http://forums.asp.net/p/1464517/3380620.aspx/1?Re+How+to+Sort+my+objects+in+Dynamic+Data+Re: How to Sort my objects in Dynamic Data? <p>&nbsp;In the databaseI added a new column called FullName and in the &quot;Computed Column Specification&quot; Formula Filed I added the formula&nbsp;<font size="2">[FirstName]</font><font color="#808080" size="2"><font color="#808080" size="2">&#43;</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">', '</font></font><font color="#808080" size="2"><font color="#808080" size="2">&#43;</font></font><font size="2">[LastName] this gives me a field in the DB&nbsp; (Where you need it to filter) that I can filter on and use to display in Drop down lists using DisplayColumn attribute.</font></p> 2009-09-01T11:12:48-04:003382517http://forums.asp.net/p/1464517/3382517.aspx/1?Re+How+to+Sort+my+objects+in+Dynamic+Data+Re: How to Sort my objects in Dynamic Data? <p>That is a solution I agree but an ugly one, isn't it?!</p> <p>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 &quot;SortByProperty&quot; and &quot;SortByColumn&quot;.</p> <p>Have you thought about this?</p> 2009-09-02T08:37:30-04:003382804http://forums.asp.net/p/1464517/3382804.aspx/1?Re+How+to+Sort+my+objects+in+Dynamic+Data+Re: How to Sort my objects in Dynamic Data? <p>&nbsp;</p> <blockquote><span class="icon-blockquote"></span> <h4>Dynamic2008</h4> <p>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 &quot;SortByProperty&quot; and &quot;SortByColumn&quot;.</p> <p></p> </blockquote> <p></p> <p>This will be&nbsp; 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. </p> <p>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</p> 2009-09-02T10:30:14-04:003384973http://forums.asp.net/p/1464517/3384973.aspx/1?Re+How+to+Sort+my+objects+in+Dynamic+Data+Re: How to Sort my objects in Dynamic Data? <p>I read from <a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27026"> here</a> 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 :)</p> <p>So how do you resolve this issue in preview 4.0?</p> <p><br> </p> <p><br> </p> 2009-09-03T09:30:20-04:003385284http://forums.asp.net/p/1464517/3385284.aspx/1?Re+How+to+Sort+my+objects+in+Dynamic+Data+Re: How to Sort my objects in Dynamic Data? <p>&nbsp;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.</p> 2009-09-03T11:53:35-04:003540285http://forums.asp.net/p/1464517/3540285.aspx/1?Re+How+to+Sort+my+objects+in+Dynamic+Data+Re: How to Sort my objects in Dynamic Data? <p>Here is&nbsp;a solution that allows you to sort a GridView&nbsp;with Visual Studio 2008 sp1.&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;</p> <pre class="prettyprint">protected void Page_Init(object sender, EventArgs e) { //Your other code // Sorting GridView1.Sort(&quot;OrderId&quot;, SortDirection.Ascending); }</pre> <p><br> </p> <p>&nbsp;</p> 2009-11-30T19:51:03-05:00