ASP.NET Dynamic Data DisplayColumn attribute causing sorting problem.

Using ASP.NET Dynamic Data with LINQ to SQL DataContext from a Northwind Database ...

When I add a DisplayColumn attribute to one of my LINQ to SQL classes entityand reference a property from my custom code in a partial class, I lose the ability to sort by this column in the generated GridView. I still lose the ability to sort, even if I refer to a non-standard property like sortColumn.

Why is this happening?

Code example:

[DisplayColumn("LastNameFirstName", "LastName", false)]
public partial class Employee
{
    public string LastNameFirstName
    {
        get { return LastName + ", " + FirstName; }
    }
}

Aaron

EDIT: sortColumnindicates the column that will be used to sort this object when it is used as a foreign key (in DropDownList), and not when it is sorted in a GridView.

+3
4

...

"sortColumn" , , ( DropDownList), GridView.

+2

, , linq to SQL T-SQL . , .

+2

You can try to override the ToString () method, which could work, but it will only filter the object referenced by the FK relationship.

0
source

Try adding [ScaffoldColumn (true)] - it can trick dynamic data to enable sorting

[DisplayColumn("LastNameFirstName", "LastName", false)]
public partial class Employee
{
    [ScaffoldColumn(true)]
    public string LastNameFirstName
    {
        get { return LastName + ", " + FirstName; }
    }
}
0
source

All Articles