Meaning of expression% # "example"%

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 does this hashtag do and when should I use it?

    
asked by anonymous 27.10.2017 / 14:41

1 answer

3

It is a simplified form of data binding , so the element already knows that it has to get the data available in the model defined above through 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>

Documentation .

    
27.10.2017 / 14:45