【问题标题】:Date value not showing in the calendar with HTML5 support in VS2012VS2012 中支持 HTML5 的日历中未显示日期值
【发布时间】:2013-05-23 11:52:45
【问题描述】:

我有一个Form View 中有一个文本字段,该文本字段绑定到一个2路绑定控件,代码如下:

<td class="table-4">
   <asp:TextBox ID="txtDOB" runat="server" Text='<%# BindItem.DOB%>' TextMode="Date" Width="200px"</asp:TextBox>
</td>

我使用 TextMode 作为日期,这将导致在浏览器中显示日历。

在模型实体类中,我将 DOB 定义为:

<Display(Name:="Date of Birth"), DataType(DataType.DateTime), DisplayFormat(ApplyFormatInEditMode:=True, DataFormatString:="{0:yyyy-MM-dd}")> _
Public Property DOB() As Date?

问题: 当使用谷歌浏览器或 Opera 时,它们在处理和兼容 HTML5 元素方面表现出色,txtDOB 字段不显示从数据库绑定的日期数据值,而是显示的是: 1- 在 Chrome 中,显示 yyyy-mm-dd,这是我使用的日期格式 2- 在 Opera 中,txtbox 是空的。

点击该字段时,两个浏览器都会显示日历。

为什么日历打开时文本字段中未显示的有界日期数据也未标记/选择?

注意: 在 IE 中,我将其视为 normat txtField,其日期值从数据库绑定,当然没有日历视图,因为 IE 版本 9 不完全支持 HTML5,导致无法理解标签(TextMode="日期")

使用的技术: - 对比 2012 - 实体框架 4.5

【问题讨论】:

    标签: html visual-studio-2012


    【解决方案1】:

    您必须将格式设置为 ISO 日期格式:

    <EditItemTemplate>
      <asp:TextBox ... Text='<%# Bind("BirthDate","{0:yyyy-MM-dd}") %>' TextMode="Date"></asp:TextBox>
    </EditItemTemplate>
    

    【讨论】:

    • 是的,你是对的。我已经添加了这一行,它工作正常 Bind("BirthDate","{0:d}")。抱歉,我没有按照之前的回答更新我的问题。感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 2014-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多