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?

Paulo Morgado
  • 14,111
  • 3
  • 31
  • 59

1 Answers1

0

The problem is that the parser is unable to keep track of the quotations.

The solution is to use single quotes in the markup and keep double quotes in the C#/VB:

<asp:Panel runat="server" Visible='<%#(bool)Eval("IsBoolean")%>'>X</asp:Panel>
Paulo Morgado
  • 14,111
  • 3
  • 31
  • 59