i’ve the following code, it’s supposed to check if a variable from a DataList (Month) it’s the same as a variable called mesActual, they’re text (Like December/November)
<li id="Li1" class='<%# (Convert.ToBoolean(Convert.ToString(Eval("Month")) == Convert.ToString(mesActual))) ? "activa" : "no-activa" %>'>
<asp:LinkButton ID="lnkbtn" runat="server" CommandName="Select" CommandArgument='<%#Eval("Month")%>'><%#Eval("Month")%></asp:LinkButton>
<div class="btn"><span><asp:Label ID="lbltot" runat="server"></asp:Label></span></div>
</li>
On page load, it seems to work, first item is selected and assigned the class “activa”, but when i click on the button, it reloads the page, i can see my variable “mesActual” changed, but the class of the li doesn’t change.
I’m missing something?
Thanks!
Try comparing using Equals method instead of the == operator. This will compare the string values as opposed to references.
Also you do not need to wrap it in Convert.ToBoolean() as the result of the Equals method will return a bool.
Eval(“Month”).Equals(Convert.ToString(mesActual)) ? “activa” : “no-activa”