Asp – Sorting by multiple fields using DisplayColumnAttribute in Asp.Net Dynamic Data App

asp.netdynamic-data

I've got a dynamic data app, and I want to sort based on multiple fields like so..

<DisplayColumn("FieldName", "Field1, Field2")> _

DisplayColumn doesn't seem to support more than one field?

Best Answer

The DisplayColumn attribute's SortColumn param specifies the column that will be used to sort this entity when it is used as a foreign key (ex: in a DropDownList), not when it is being sorted in the GridView (or being sorted in the DB).

see SO here as well: ASP.NET Dynamic Data DisplayColumn Attribute Causing Sorting Issue

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

If this is still what you are looking for (sorting in DropDownLists only, not the DB) you can sort on multiple columns by creating a custom property in the entity that combines those two columns.

example:

[DisplayColumn("FieldName", "SortColumn")]
public partial class Employee
{
    public string SortColumn
    {
        get { return Field1 + Field2; }
    }
}
Related Topic