What are the capabilities of the DisplayColumn attribute? I would like to be able to display the combination of two fields from the table, something like FirstName and LastName for the user to be able to distinguish between names in the drop down of a foreign
table. Is it possible yet?
You can do this today. Make a new column on the table in your data model and set your DisplayColumn to it. For example in Northwind you can do this:
[DisplayColumn("TestColumn")]
public partial class Category {
public string TestColumn {
get { return CategoryName + "Test"; }
}
}
I make a partial class to extend the data model Category class. Then I create my own new column TestColumn and I can make it return whatever I want. If the table contained a First + Last I could return that. Hope this helps.
...Scott
Scott Hunter
PM, ASP.NET Team, Microsoft
Marked as answer by avalutions on Apr 18, 2008 02:52 PM
Yet another way to do this is to override ToString() in the partial class and return what you want displayed. It will then get picked up instead of a 'regular' column.
avalutions
Member
2 Points
11 Posts
Multiple Columns for DisplayColumn?
Apr 12, 2008 06:46 AM|LINK
What are the capabilities of the DisplayColumn attribute? I would like to be able to display the combination of two fields from the table, something like FirstName and LastName for the user to be able to distinguish between names in the drop down of a foreign table. Is it possible yet?
scothu
Participant
1436 Points
291 Posts
Microsoft
Moderator
Re: Multiple Columns for DisplayColumn?
Apr 12, 2008 05:21 PM|LINK
You can do this today. Make a new column on the table in your data model and set your DisplayColumn to it. For example in Northwind you can do this:
[DisplayColumn("TestColumn")]
public partial class Category {
public string TestColumn {
get { return CategoryName + "Test"; }
}
}
I make a partial class to extend the data model Category class. Then I create my own new column TestColumn and I can make it return whatever I want. If the table contained a First + Last I could return that. Hope this helps.
...Scott
PM, ASP.NET Team, Microsoft
davidebb
Contributor
7006 Points
1366 Posts
Microsoft
Re: Multiple Columns for DisplayColumn?
Apr 13, 2008 03:09 PM|LINK
Yet another way to do this is to override ToString() in the partial class and return what you want displayed. It will then get picked up instead of a 'regular' column.
thanks,
David