<asp:TextBox ID="txtDate" runat="server" Value="<%= DateTime.Today.ToShortDateString() %>" />Value="<%= DateTime.Today.ToShortDateString() %>"不在文本字段中写入日期,而是在整个字符串中写入日期。我做错了什么?
发布于 2010-05-30 16:38:49
使用JavaScript和jQuery:
var now = new Date();
$('#txtDate').text(now.getDate() + '/' + now.getMonth()+ '/' + now.getYear());或者普通的JavaScript:
var now = new Date();
document.getElementById('txtDate').value = now.getDate() + '/' + now.getMonth()+ '/' + now.getYear();或者在标记中(使用System.Web.UI.WebControls.TextBox.Text属性,它没有Value属性):
<asp:TextBox ID="txtDate" runat="server" Text="<%# DateTime.Today.ToShortDateString() %>" />然后调用this.DataBind();或者不调用页面,而调用TextBox的父控件。
发布于 2010-05-30 16:47:09
正如您所看到的,您不能使用<%= %>构造来设置服务器控件的属性。
在标记中设置属性的常用方法是使用<%# data-binding expression %>
https://stackoverflow.com/questions/2937951
复制相似问题