Why does C# expect a ";" in my ItemTemplates?

190 views Asked by At

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 run the page, I get the following error: CS1002: ; expected with the line directly under <ItemTemplate> highlighted. Why is this? I thought that When you use <%# XXXXX %>, you don't use a semicolon.

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

2

There are 2 answers

0
Vivian River On BEST ANSWER

Oops, I just realized that I have an extra ")" which caused the error.

<%# ((MyType)Container.DataItem).FirstName) %> needs to be _<%# ((MyType)Container.DataItem).FirstName %>

2
Scoregraphic On

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>