Meaning of expression <%# "example" %>

Asked

Viewed 73 times

6

I’m used to seeing expressions like <%= "Olá" %> but I came across a code:

<asp:Image 
     id="imagemStatusDocumento" 
     runat="server" 
     ImageUrl='<%# ObtemImagem(Eval("NomeTipo")) %>' 
/>

Highlighting the part that matters, part of the code where we have an Octothorpe(Hashtag):

<%# ObtemImagem(Eval("NomeTipo")) %>

Could you tell me what this one does hashtag and when to use it?

1 answer

3


It is a simplified form of data Binding, then the element already knows that it has to take the available data in the model defined above through the DataSourceID. Example:

<asp:FormView ID="FormView1"
  DataSourceID="SqlDataSource1"
  DataKeyNames="ProductID"     
  RunAt="server">

  <ItemTemplate>
    <table>
      <tr>
        <td align="right"><b>Product ID:</b></td>       
        <td><%# Eval("ProductID") %></td>
      </tr>
      <tr>
        <td align="right"><b>Product Name:</b></td>     
        <td><%# Eval("ProductName") %></td>
      </tr>
      <tr>
        <td align="right"><b>Category ID:</b></td>      
        <td><%# Eval("CategoryID") %></td>
      </tr>
      <tr>
        <td align="right"><b>Quantity Per Unit:</b></td>
        <td><%# Eval("QuantityPerUnit") %></td>
      </tr>
      <tr>
        <td align="right"><b>Unit Price:</b></td>       
        <td><%# Eval("UnitPrice") %></td>
      </tr>
    </table>                 
  </ItemTemplate>                 
</asp:FormView>

I put in the Github for future reference.

Documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.