views:

37

answers:

1

I have two tables (Person and Location)

In the Dynamic Data Site, when adding Location info, I am need to choose a person from the dropdown box which is populated via a FK. That dropdown box defaults to the field in "Person" that is titled "fname" which is first name, so it looks like "Jim" or "Steve".

I'm trying to have that dropdown box display the full name of the person it references which would be combining the fields fname and lname.

Would I do this inside a Field Template? Metadata? I'm kind of stuck on this.

If I look at the FieldTemplate for ForeignKey_Edit I see this:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (DropDownList1.Items.Count == 0)
        {
            if (Mode == DataBoundControlMode.Insert || !Column.IsRequired)
            {
                DropDownList1.Items.Add(new ListItem("[Not Set]", ""));
            }
            PopulateListControl(DropDownList1);
        }

        SetUpValidator(RequiredFieldValidator1);
        SetUpValidator(DynamicValidator1);
    }

and it seems like I should be able to make something similar to "PopulateListControl" and use that instead, but I have no idea where this method even resides.

Any ideas?

A: 

Found it. I needed to override the ToString() method of my class to return a combination of properties.

[MetadataType(typeof(PersonMetaData))]
public partial class Person
{
    public override string ToString()
    {
        return lname.ToString() + ", " + fname.ToString();
    }

}
Shadyn