0

ASP.NET 2.0

As much as I try, I can't seem to bind the Visible property to data item property:

<asp:Panel runat="server" Visible="<%#(bool)Eval("IsBoolean")%>">X</asp:Panel>

I always get this error:

Cannot create an object of type 'System.Boolean' from its string representation '"<%#(bool)Eval("IsBoolean")%' for the 'Visible' property.

But this works:

<asp:Panel runat="server" Visible="<% true %>">X</asp:Panel>

What am I doing wrong? I mean, besides using ASP.NET 2.0?

4

1 回答 1

0

问题是解析器无法跟踪引用。

解决方案是在标记中使用单引号并在 C#/VB 中保留双引号:

<asp:Panel runat="server" Visible='<%#(bool)Eval("IsBoolean")%>'>X</asp:Panel>
于 2016-09-21T15:07:52.797 回答