如何更改在 DynamicData 站点中呈现过滤器和外键列的方式?
好吧,我的标题没有帮助。但读一下帖子你就会明白。
我想要做什么:
假设我的 SQl Server 中有一个包含 2 列的 Flyer 表:
- FlyerID (int)(PK)
- FlyerDate (smalldatetime)
FlyerID 是其他表(例如 Store 表)上的外键。 Store 有 3 列:
- StoreID (int)(PK)
- Name (nvarchar)
- FlyerID (int)(FK) 与的关系 传单表
现在,在 DynamicData 站点上,我将拥有“商店”页面和“传单”页面。我想使用我的自定义格式显示 FlyerDate。例如,格式为 MMM-dd-yyyy。
在 Flyers 页面上,我按照 asp.net/learn/3.5-SP1/video-291.aspx
上的教程视频实现的方式效果很好,显示了 FlyerDate 列的自定义格式。
但是,在“商店”页面上,传单列值(超链接)不会以我的自定义格式显示日期。另外,在过滤器(下拉列表)中不显示自定义格式。
建议的失败解决方案位于:http://ericphan.info/development/asp-net-dynamic-data-display-custom-text-in-a-foreign-key-dropdownlist-combobox 给出错误“显示列 'DisplayDate ' 为表指定的内容不存在。”
.Net Framework 4.0 BETA 和实体框架。
[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; }
}
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 with 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; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道应该做什么。覆盖 ToString:
I know what it should be done. Override ToString:
您的属性 DisplayDate 具有正确的格式,因此只需在元数据中引用它:
Your property DisplayDate has the correct formatting, so just reference it in your metadata: