问题
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