开发者

How to change the way filters and foreign-key columns are rendered in DynamicData site?

Ok, my title doesn't help. But read the post and you'll understand.

What i want to do:

Imagine I have a Flyer table wi开发者_StackOverflowth 2 columns in my SQl Server:

  • FlyerID (int)(PK)
  • FlyerDate (smalldatetime)

FlyerID is a foreign key on other tables, for example Store table. Store has 3 columns:

  • StoreID (int)(PK)
  • Name (nvarchar)
  • FlyerID (int)(FK) relationship with Flyer table

Now, at the DynamicData site, I will have the Stores page and the Flyers page. I want to display FlyerDate using my custom format. The format is MMM-dd-yyyy, for example.

At the Flyers page, the way I implemented following the tutorial video at: asp.net/learn/3.5-SP1/video-291.aspx works perfectly, displaying my custom format for the FlyerDate column.

At the Stores page however, the Flyer column values (which are hyperlinks) don't show the date in my custom format. Also, in the Filter (dropdown list) doesn't show custom format.

Suggested Failed Solution at: http://ericphan.info/development/asp-net-dynamic-data-display-custom-text-in-a-foreign-key-dropdownlist-combobox gives error "The display column 'DisplayDate' specified for the table does not exist."

.Net Framework 4.0 BETA and Entity Framework.

[DisplayColumn("DisplayDate", "FlyerDate", true)]
[MetadataType(typeof(FlyerMetadata))]
public partial class Flyer
{

    [ScaffoldColumn(true)]
    public string DisplayDate
    {
        get { return this.FlyerDate.ToString("MMM-dd-yyyy"); }
    }

}

public class FlyerMetadata
{
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MMM-dd-yyyy}")]
    public DateTime FlyerDate { get; set; }
}


I know what it should be done. Override ToString:

public partial class Flyer
{

    public override string ToString()
    {
        return this.FlyerDate.ToString("MMM-dd-yyyy");
    }

}


Your property DisplayDate has the correct formatting, so just reference it in your metadata:

public class FlyerMetadata
{
    public String DisplayDate { get; set; }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜