开发者

Why does C# expect a ";" 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 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 &开发者_StackOverflow中文版lt;%# Eval("FirstName") %> and that seems to work.


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

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


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜