Inline Code in markup page in ASP.NET Webforms?

谁说我不能喝 提交于 2019-12-24 10:35:32

问题


Is something similiar to the following pseduocode possible on server side controls?

<asp:Label runat="server" ID="lbl" Text=<%=DateTime.Now.ToString(); %> />

I.e. assigning attributes.


回答1:


This will work for databound controls, e.g.

<asp:Label runat="server" ID="lbl" Text="<%# DateTime.Now.ToString() %>" />

Then in your code behind, you'll need to call lbl.DataBind().




回答2:


Try this:

<asp:Label runat="server" ID="lbl" Text='<%=DateTime.Now.ToString()%>' /> 


来源:https://stackoverflow.com/questions/7889035/inline-code-in-markup-page-in-asp-net-webforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!