How to bind a label text property in markup

Basically, I would like to find a way to do something like:

<asp:Label ID="lID" runat="server" AssociatedControlID="txtId" Text="<%# MyProperty %>"></asp:Label> 

I know that I can install it from the code (by writing lId.Text = MyProperty), but I would prefer to do this in the markup, and I just can't find a solution. (MyProperty is a string property) greetings

+3
Sep 16 '08 at 15:20
source share
8 answers

Code expressions are also an option. They can be used inside quotes in ASP tags, unlike standard <% =%> tags.

General syntax:

 <%$ resources: ResourceKey %> 

There is a built-in expression for appSettings:

 <%$ appSettings: AppSettingsKey %> 

More on this here: http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionBuilder.aspx

+10
Sep 16 '08 at 18:08
source share

You can do

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

And then in the code.DBeb () file.

+8
Sep 16 '08 at 16:11
source share

Leave the markup as is and call the .DataBind () page; in your code.

+2
Sep 16 '08 at 15:23
source share
 <asp:Label id="lID" runat="server"><%= MyProperty %></asp:Label> 

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

+2
Sep 16 '08 at 15:26
source share

Call lID.Databind () from code

0
Sep 16 '08 at 15:22
source share
 <div> <%=MyProperty"%></div> 
0
Sep 16 '08 at 15:28
source share

When you use the declaration <% # MyProperty%>, you need to bind it to it, but when using <% = MyProperty%> you don’t (which looks like just writing Response.Write (MyProperty).

0
Sep 16 '08 at 17:55
source share

You can do it:

 <asp:Label ID="lblCurrentTime" runat="server"> Last update: <%=DateTime.Now.ToString()%> </asp:Label> 
0
Jun 03 '10 at 19:08
source share



All Articles