I am trying to set the visible property for a label to either true or false depending on a condition. This is in ASPX page. I am doing something wrong and getting error when this is executed.
<td><asp:Label ID="Label23" runat="server" Text='CERTIFIED'
Visible='<%# DataBinder.Eval(Container.DataItem, "IsAuthorized") > 0%>'>
</asp:Label></td>
Error I am getting is below.
Compiler Error Message: CS0019: Operator '>' cannot be applied to operands of type 'object' and 'int'
What changes need to be done?
All I need to do set the visible property of the LABEL to true when 'IsAuthorized' is greater than zero.
That's because you have a syntax error, you silly bunny.
Here you are, it should be like this:
<td><asp:Label ID="Label23" runat="server" Text='CERTIFIED' Visible='<%# DataBinder.Eval(Container.DataItem, "IsAuthorized") %>' /></td>
You had an extra >
and a 0
in there somewhere.
Also, since you aren't doing anything between the <asp:Label
and </asp:Label>
, you can close it with an end slash and skip a separate ending tag. Like this <asp:Label ... />
ALSO, sometimes trying to set a visible property like that causes problems, the program can complain that the value wasn't a Boolean. You might want to also ad an explicit conversion like this:
Visible='<%# Convert.ToBoolean(DataBinder.Eval(Container.DataItem, "IsAuthorized")) %>'
Assuming that IsAuthorized
is a bit type, just cast it to a boolean:
Visible='<%#Convert.ToBoolean(Eval("IsAuthorized"))%>'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With