Asp – Change which field is displayed in a dropdown

asp.netdynamic-data

I have a Dynamic Data website and while inserting a record into a table, the foreign key relationship shown as a drop-down uses the wrong field for it's select item text value.

How can I change the drop-down such that when working with this one table, it will use a different column as the value in the drop-down?

thank you

Best Answer

The solution is to add a partial class with some attributes from the System.ComponentModel.DataAnnotations namespace & assembly. Notice the [DisplayColumn("Description")] below. That's what field is used to render as the text in a list.

Further reading

[MetadataType(typeof(ProductMetadata))]
**[DisplayColumn("Description")]**
[ScaffoldTable(true)]
public partial class Product
{
}

public class ProductMetadata
{
    [UIHint("TextReadOnly")]
    public string CreatedBy;

    [UIHint("TextReadOnly")]
    public string CreatedDate;

    [ScaffoldColumn(false)]
    public EntityCollection<OrderItem> OrderItem;
}
Related Topic