直接在ASPX页面渲染DateTime.Now [英] Render DateTime.Now directly in the ASPX page

查看:285
本文介绍了直接在ASPX页面渲染DateTime.Now的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做的直接以下到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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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