好吧,我的标题没有帮助。但是阅读这篇文章,您就会明白。
我想做什么:
假设我的 SQl Server 中有一个包含 2 列的 Flyer 表:
- 传单 ID(整数)(PK)
- FlyerDate (smalldatetime)
FlyerID 是其他表的外键,例如 Store 表。商店有 3 列:
- 商店 ID(整数)(PK)
- 姓名(nvarchar)
- FlyerID (int)(FK) 关系 传单 table
现在,在 DynamicData 网站上,我将拥有商店页面和传单页面。我想使用自定义格式显示 FlyerDate。例如,格式为 MMM-dd-yyyy。
在 Flyers 页面上,我按照以下教程视频实现的方式:asp.net/learn/3.5-SP1/video-291.aspx
完美运行,显示我的 FlyerDate 自定义格式专栏。
但是,在 Stores 页面上,Flyer 列值(超链接)不会以我的自定义格式显示日期。此外,在过滤器(下拉列表)中不显示自定义格式。
建议的失败解决方案位于:http://ericphan.info/development/asp-net-dynamic-data-display-custom-text-in-a-foreign-key-dropdownlist-combobox给出错误“为表指定的显示列‘DisplayDate’不存在。”
.Net Framework 4.0 测试版和 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; }
}
最佳答案
我知道应该做什么。覆盖 ToString:
public partial class Flyer
{
public override string ToString()
{
return this.FlyerDate.ToString("MMM-dd-yyyy");
}
}
关于c# - 如何更改过滤器和外键列在 DynamicData 站点中的呈现方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2074446/