How to 'bind' Text property of a label in markup

后端 未结 8 1121
忘掉有多难
忘掉有多难 2020-12-06 03:41

Basically I would like to find a way to ddo something like:



        
相关标签:
8条回答
  • 2020-12-06 04:07

    When you use <%# MyProperty %> declaration you need to databind it, but when using <%= MyProperty %> you don't (which is similar to just writing Response.Write(MyProperty).

    0 讨论(0)
  • 2020-12-06 04:11
    <asp:Label id="lID" runat="server"><%= MyProperty %></asp:Label>
    

    since asp.net tags do not allow <% %> constructs, you cannot use Text="<%= MyProperty %>".

    0 讨论(0)
  • 2020-12-06 04:14

    Leave the markup as is and make a call to Page.DataBind(); in your code behind.

    0 讨论(0)
  • 2020-12-06 04:18

    You can do

    <asp:Label runat="server" Text='<%# MyProperty %>' />
    

    And then a Page.DataBind() in the codebehind.

    0 讨论(0)
  • 2020-12-06 04:19

    You can do this:

    <asp:Label ID="lblCurrentTime" runat="server">
        Last update: <%=DateTime.Now.ToString()%>
    </asp:Label>
    
    0 讨论(0)
  • 2020-12-06 04:28

    Call lID.Databind() from code-behind

    0 讨论(0)
提交回复
热议问题