Monday, 8 February 2010

Asp.Net Dynamic Data – DisplayColumn Part 1

This post is broken in 2 to cover the basic use of the attribute and then some of its options in the next post.

This attribute doesn’t appear on the meta information that controls display, but rather it is meta information on the partial class that matches the entity in the ORM.

When a table contains a foreign key to another table that is included in the ORM dynamic data normally uses the first string/text column that it finds in the related table to display to the user as link in both the list and detail view and a dropdown list in the edit view.

This attribute provides the ability for you to choose which column you want to use to display for the foreign key rather than the column dynamic data would choose.

To implement this attribute you first have to create the partial class that matches the entity in the ORM (see my post here about a gotcha with extending the data context) and then add the attribute:
partial class Customer

By doing this you will then see the Customer.ContactName instead of the Contact.CompanyName value displayed for the link in the list and detail views and used to populate the drop down list in the edit view.

Check here for the MSDN definition of the attribute.

1 comment:

  1. Thank you for the info. It sounds pretty user friendly. I guess I’ll pick one up for fun. Thank u.