问题描述
我试图做的直接以下到aspx页面,但它没有显示的日期值。我不想从后面code做到这一点。我思念的东西这里小? PLS建议。
I am trying to do the following directly into the aspx page but it is not showing the date value. I dont want to do it from the code behind. Am i missing something small here? Pls suggest.
<asp:Literal ID="ltrDate" Text='<% DateTime.Now.ToLongTimeString() %>' runat="server"></asp:Literal>
即使在EX pression&LT使用散列;%#DateTime.Now.ToLongTimeString()%>无效
Even the use of hash in the expression <%#DateTime.Now.ToLongTimeString() %> does not work.
推荐答案
在使用数据绑定前pression如&LT;%#DateTime.Now.ToLongTimeString()%GT;
,那么你必须调用的Page.DataBind()
(或 ltrDate.DataBind()
如果这是从$ C $的唯一数据绑定控件)C-落后(如在Page_Load中)。
When using a databinding expression such as <%# DateTime.Now.ToLongTimeString() %>
, then you have to call Page.DataBind()
(or ltrDate.DataBind()
if that's the only databound control) from your code-behind (e.g. in Page_Load).
这篇关于直接在ASPX页面渲染DateTime.Now的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!