views:

564

answers:

2

I am using ASP.NET dynamic data for the data adminstration tasks for a Silverlight app that I built. It saved a ton of time not having to write all of the admin screens you typically have to create for end users to manage the data.

One thing I cannot figure out how to sort the items in the drop downs that appear on the screens - either the filter dropdowns on the list views or on the data entry screens.

Do I specify that somewhere in the EDM partial classes or in the ASP.NET DD field templates? or somewhere else?

All I need to do is sort alphabetically by the display value- they appear to be in random order.

thanks Michael

+1  A: 

The answer to your question can be found here, about halfway down the page:

http://csharpbits.notaclue.net/2008/08/dynamic-data-and-field-templates-second.html

In the Cascase.ascx.cd FilterControl and Cascade_Edit.ascx.cs FieldTemplate you will find a method GetChildListFilteredByParent. This returns the values for the filtered DropDownList, but as you will see this list is an unordered list. To add sorting to this list we need to add a Linq OrderBy clause.

Robert Harvey
+1 because this works, but @Aaron Hoffman's answer was far simpler.
David Stratton
+5  A: 

Use the DisplayColumn Attribute in the System.ComponentModel.DataAnnotations Namespace.

http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displaycolumnattribute.aspx

ex:

[DisplayColumn("LastName", "LastName")]
public partial class Employee
{


}
Aaron Hoffman
Nice one! Thanks for the tip! Worked a charm.
Andrew

related questions