Home > DeveloperSection > Forums > Check variable to set class value at runtime
Goti Bandu

Total Post:119

Points:835
Posted on    August-25-2014 1:14 AM

 C# C# 
Ratings:


 1 Reply(s)
 637  View(s)
Rate this:

I've the following code, it's supposed to check if a variable from a DataList, it's the same as a variable called mesActual,  

      <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.



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    August-25-2014 2:15 AM

Hi Goti, 

Try runat="server", <%# %> only fires on DataBind():

<li id="Li1" runat="server" class='<%# Convert.ToString(Eval("Month")) == Convert.ToString(mesActual) ? "activa" : "no-activa" %>'>


Don't want to miss updates? Please click the below button!

Follow MindStick