具有TextMode ="Date"的TextBox;不显示数据 [英] TextBox with TextMode="Date" does not show data

查看:49
本文介绍了具有TextMode ="Date"的TextBox;不显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Gridview,其DateTime列的定义如下:

I have a Gridview, with a DateTime column defined like this:

<asp:TemplateField>
  <EditItemTemplate>
     <asp:TextBox ID="txtDate" Text='<%# Item.Date.ToShortDateString() %>' runat="server" TextMode="Date"></asp:TextBox>
  </EditItemTemplate>
  <ItemTemplate>
    <asp:Label ID="lblDate" runat="server" Text='<%# Item.Date.ToShortDateString() %>'></asp:Label>
  </ItemTemplate>
</asp:TemplateField>

日期将显示在网格中,并且当我从网格中编辑一行时它会正确保存.唯一的问题是,在一行的编辑模式"下输入时,"txtDate"不显示当前值.它显示"mm/dd/yyyy",而不是来自绑定的实际值.而且我不知道为什么.但是,当我删除属性TextMode ="Date"时,实际值会正确显示.

The date gets displayed in the grid, and it gets saved correctly when I edit a row from the grid. The only problem is that "txtDate" doesn't display the current value when entering in "edit mode" of a row. It displays "mm/dd/yyyy" instead of the actual value coming from the bind. And I don't know why. Nonetheless, when I remove the property TextMode="Date", the actual value displays correctly.

有什么想法吗?谢谢!

推荐答案

当浏览器无法解析给定日期时,就会在Google Chrome中发生.您也应该在浏览器的控制台中收到有关此警告.Google Chrome浏览器期望格式为 yyyy-MM-dd ,因此:

This occurs in Google Chrome when the browser can't parse the given date. You should be getting a warning about that in the browser's console as well. Google Chrome expects the format to be yyyy-MM-dd, so e.g.:

Item.Date.ToString("yyyy-MM-dd");

这篇关于具有TextMode ="Date"的TextBox;不显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆