Link to home
Start Free TrialLog in
Avatar of Rajiv Aarya
Rajiv Aarya

asked on

Change style using Condition in Repeater

Hi I'm using Repeater and have to change display property on condition.  For that, I tried

<span class="order_in_status" <%# Convert.ToInt32(Eval("OrderCreated"))%>  == 1 ? "style='display:block;'" : "style='display:none;'" ></span>

But it's not working.

Someone suggested me

<span class="order_in_status" <%# Convert.ToInt32(Eval("OrderCreated"))  == 1 ? "style='display:block;'" : "style='display:none;'" %>></span>

This also not works.  Can anyone gives me the perfect solution
Avatar of Imran Javed Zia
Imran Javed Zia
Flag of Pakistan image

Please try following:

<span class="order_in_status" style='display:<%# Convert.ToInt32(Eval("OrderCreated"))  == 1 ? "block;" : "none;" %>'></span>


<span class="order_in_status" style='display:<%# Convert.ToInt32(Eval("OrderCreated"))  == 1 ? "block !important;" : "none !important;" %>'></span>
Avatar of Rajiv Aarya
Rajiv Aarya


Still getting an error in both the cases.
Compiler Error Message: BC30201: Expression expected.
I've attached the screen shot
Avatar of Camillia
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you're using ASP.NET 2.0, I think the conditional operator is not supported in data binding expressions.
You can, however, create a method like
object iif(bool condition, object ifTrue, object ifFalse)
    return condition ? ifTrue : ifFalse;

Open in new window

and call it from your data binding expression:
<%# iif(Convert.ToInt32(Eval("OrderCreated"))%>  == 1, "style='display:block;'", "style='display:none;'") %>

Open in new window

No I'm not using 2.0
Dear Camillia,
I tried this
<span class="order_in_status" runat="server" visible='<%# IIf(databinder.eval(container.dataitem, "OrderCreated") = 0, "true", "false")%>'>>Hello</span>

It works but for that I've to make it server control
Is there any other solution.?
You get  the  value  of  order created field  from database or server If should be server side.
Okay.  Thank You!