列表视图中的 ASP.NET 服务器标记格式不正确错误
下面的图像按钮就像一个魅力
<asp:ListView ID="ListView1" runat="server">
<layouttemplate>
<asp:PlaceHolder id="itemPlaceholder" runat="server" />
</layouttemplate>
<ItemTemplate>
<asp:ImageButton onmouseover="javascript:show('Error1');" ID="btnContainsError" runat="server"/>
</ItemTemplate>
</asp:ListView>
但现在我想“让它工作”列表视图中的每条记录
所以对于记录1它应该像
<asp:ImageButton onmouseover="javascript:show('Error1');"
ID="btnContainsError" runat="server"/>
第二条记录
<asp:ImageButton onmouseover="javascript:show('Error2');"
ID="btnContainsError" runat="server"/>
等等......
不幸的是我的一些尝试制作,如下所示,产生 Server tag is not wellforming
错误
<asp:ImageButton onmouseover="javascript:show('<%# "Error" & DataBinder.Eval(Container.DataItem, "Counter") %>');" ID="btnContainsError" runat="server"/>
那么你能指出我正确的方法吗?
The Following Image button works like a charm
<asp:ListView ID="ListView1" runat="server">
<layouttemplate>
<asp:PlaceHolder id="itemPlaceholder" runat="server" />
</layouttemplate>
<ItemTemplate>
<asp:ImageButton onmouseover="javascript:show('Error1');" ID="btnContainsError" runat="server"/>
</ItemTemplate>
</asp:ListView>
But now I would like to "make it work" for every record within the list view
So for record 1 it should be like
<asp:ImageButton onmouseover="javascript:show('Error1');"
ID="btnContainsError" runat="server"/>
for the second record
<asp:ImageButton onmouseover="javascript:show('Error2');"
ID="btnContainsError" runat="server"/>
and so on...
Unfortunately some of the tries i made, like the following, produce the Server tag is not well formed
error
<asp:ImageButton onmouseover="javascript:show('<%# "Error" & DataBinder.Eval(Container.DataItem, "Counter") %>');" ID="btnContainsError" runat="server"/>
So could you please point me, the correct way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
问题是你不能将该连接放在 <%# %> 内部。控件内的标签。在这种情况下,我通常做的是在表单对象上创建一个公共属性,然后从控件内调用该属性。例如,将其放在表单对象的代码后面:
然后您可以将以下内容放入您的 aspx 页面中:
这应该可以工作。
The problem is that you can't put that concatenation inside of the <%# %> tags within the control. What I usually do in this situation is create a public property on the form object and then call that property from within the control. For Example put this on your form object on the code behind :
And then you can put the following in your aspx page:
This should work.
如果您在属性内使用服务器端代码标签 (
<% %>
),则需要将属性值用单引号而不是双引号括起来。尝试将 onmouseover 属性更改为:
或者,您可以在后面的代码中创建一个方法并调用它
并在后面的代码中:
if you are using server side code tags (
<% %>
) inside an attribute, you need to wrap the attribute value in single quotes instead of double quotes.Try changing your onmouseover attribute to this:
Alternatively, you can create a method in your code behind and call it
And in your code behind:
试试这个方法
Try it this way
我认为您不能在任何服务器端控件内拥有任何类型的
<%
服务器端标记 - 即带有runat="server"
的任何内容。这是未经测试的,而且我已经有一段时间没有做过任何经典的 ASP.NET 了...但是现在就开始吧!
请注意
OnItemDataBound
属性。现在在您的代码中:
I don't think you can have any type of
<%
server side tag inside any server side control - i.e. anything withrunat="server"
.This is untested and it's been a while since I've done any classic ASP.NET... but here goes!
Note the
OnItemDataBound
attribute.Now in your code: