Why C # expects ";" in my ItemTemplates?

I have a page with the following code:

      <ItemTemplate>
        <a id="el_<%# ((MyType)Container.DataItem).FirstName) %>" 
            class='activate_edit_modal' popupId="modal_window" title="Click to edit.">
          Edit
        </a>
      </ItemTemplate>

When I try to start the page, I get the following error: CS1002: ; expectedwith a highlighted line under <ItemTemplate>. Why is this? I thought that when you use <%# XXXXX %>, you are not using a semicolon.

I tried changing this to <%# Eval("FirstName") %>and it seems to work.

+3
source share
2 answers

Oh, I just realized that I have an extra ")" that caused an error.

<%# ((MyType)Container.DataItem).FirstName) %> it should be _<%# ((MyType)Container.DataItem).FirstName %>

+5
source

Have you tried single quotes for the id attribute?

<ItemTemplate>
  <a id='el_<%# ((MyType)Container.DataItem).FirstName) %>' 
    class="activate_edit_modal" popupId="modal_window" title="Click to edit.">
    Edit
  </a>
</ItemTemplate>
+1
source

Source: https://habr.com/ru/post/1789270/


All Articles