服务器标记格式不正确。有什么问题?

9
我收到了以下解析器错误消息。我该如何解决这个问题?

服务器标记格式不正确。

代码:

<a href="#" class="mySprite id<%# ((int)DataBinder.Eval(Container,"ItemIndex")) % 6 + 1%>">
2个回答

14

首先,你的锚点是客户端的,你应该给它添加一个runat="server"属性。其次,尝试按照以下方式使用它。

<a href="#" runat="server" id="mySprite1" 
class='<%# "mySprite id" + ((int)DataBinder.Eval(Container,"ItemIndex")) % 6 + 1 %>'>

3
我需要加单引号或其他标点符号吗? - Serenity
3
你不需要使用 runat="server",只要你不在数据绑定事件中使用 html 控件(或者 label 的 associatedControl 属性)! - user57508
2
@Andreas:是的,我知道,谢谢。@Zain:单引号丢失了,现在已经解决了,谢谢。 - Serenity

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接