Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Dynamic Data : How to Specify Sort Order of Items in Dropdown List

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

like image 791
MIantosca Avatar asked Jun 16 '09 02:06

MIantosca


2 Answers

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
{


}
like image 130
Aaron Hoffman Avatar answered Sep 28 '22 03:09

Aaron Hoffman


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.

like image 26
Robert Harvey Avatar answered Sep 28 '22 03:09

Robert Harvey