如何在标记中“绑定”标签的Text属性
基本上我想找到一种ddo的方法:
<asp:Label ID="lID" runat="server" AssociatedControlID="txtId" Text="">
我知道我可以从后面的代码设置它(写lId.Text = MyProperty),但我更喜欢在标记中进行,我似乎无法找到解决方案。 (MyProperty是一个字符串属性)欢呼
代码表达式也是一种选择。 与标准<%=%>标记不同,它们可以在ASP标记中的引号内使用。
一般语法是:
<%$ resources: ResourceKey %>
appSettings有一个内置表达式:
<%$ appSettings: AppSettingsKey %>
有关这方面的更多信息: http : //weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionBuilder.aspx
你可以做
然后是代码隐藏中的Page.DataBind()。
保留标记,并调用Page.DataBind(); 在你的代码背后。
<%= MyProperty %>
由于asp.net标签不允许<%%>构造,因此不能使用Text =“<%= MyProperty%>”。
<%=MyProperty"%>
从代码隐藏中调用lID.Databind()
当您使用<%#MyProperty%>声明时,您需要对其进行数据绑定,但在使用<%= MyProperty%>时则不需要(这与编写Response.Write(MyProperty)类似)。
你可以这样做:
Last update: <%=DateTime.Now.ToString()%>