views:

356

answers:

3

I am using ASP.net Dynamic Data scaffolding. I realize that for a table like

table1: EducationLevel (id,levelname,modby,modon)

table2: Course(id,coursename,modby,modon,belongsToEduLevel)

where belongsToEduLevel is the FK. In this case dynamic data never shows levelname in the grid instead, it shows

Operations | Modon | EducationPrograms

How do I change this?? Can I modify the select statement generated.

+2  A: 

If I understand you correctly the column you want to be displayed in not being displayed, you want the FK column to be displayed not the text value?

If so all you need to do is apply the DisplayColumn to the table that the FK references and slecte the PK as the column you want to display.

i.e. [DisplayColumn("Id")]

Id is the name of the column to display in FK relationships and Filters.

Wizzard
let me try out that bit
Perpetualcoder
+1  A: 

If you don't have customized class created yet for Courses, create the following:

[ScaffoldTable(true)]
[MetadataType(typeof(CourseMetaData))]
public partial class Course
{

}
[DisplayName("Courses")]
public class CourseMetaData
{
    [DisplayName("Course ID")]
    public object CourseID { get; set; }

    [DisplayName("Course Name")]
    public object CourseName { get; set; }

    [DisplayName("Modified By")]
    public object ModifiedBy { get; set; }

    [DisplayName("Modified By")]
    public object ModifiedBy { get; set; }

    [DisplayName("Modified On")]
    [DisplayFormat(DataFormatString = "{0:MM-dd-yyyy}")]
    public object ModifiedOn { get; set; }

    [DisplayName("Level Name")]
    public object EducationLevelName { get; set; }

}

And if you don't have one for Education Levels, grab this one:

[ScaffoldTable(true)]
[DisplayColumn("EducationLevelName")]
[MetadataType(typeof(EducationLevelMetadata))]
public partial class EducationLevel : INotifyPropertyChanging, INotifyPropertyChanged
{

}

[DisplayName("Education Levels")]
public class EducationLevelMetadata
{
    [DisplayName("Education Level ID")]
    public object EducationLevelID { get; set; }

    [DisplayName("Education Level Name")]
    public object EducationLevelName { get; set; }

    [DisplayName("Education Level Modified By")]
    public object EducationLevelModBy { get; set; }

    [DisplayName("Education Level Modified On")]
    [DisplayFormat(DataFormatString = "{0:MM-dd-yyyy}")]
    public object EducationLevelModOn { get; set; }
}
RSolberg
A: 

And if that's not entirly what you want you could override the ToString() method which will let you have a calculated value displayed:

[MetadataType(typeof(Message_MD))]
public partial class Message
{
    public override String ToString()
    {
        return MessageID.ToString() + ", " + Subject;
    }
    public partial class Message_MD
    {
        public object MessageID { get; set; }
        public object Subject { get; set; }
        public object Body { get; set; }
        public object SMSBody { get; set; }
    }
}

Here I have the PK Id and some text shown

i.e. 12, Test Message

Hope this helps :D

Wizzard