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
Rajiv AaryaAsked:
Who is Participating?
Can you use the "visible" property...or  change your code to use Iff?

Something like this

visible='<%# IIf(databinder.eval(container.dataitem, "OrderCreated") = 1, "false", "true")%>'>

Open in new window

In one of my old projects, I have something like this

<td style='font-size: 8pt; <%# (Eval("Provider").ToString() == "true") ? "Font-Weight:Bold;" : "" %>'>

Open in new window

Imran Javed ZiaConsultant Software Engineer - .NET ArchitectCommented:
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>
Rajiv AaryaAuthor Commented:
Still getting an error in both the cases.
Compiler Error Message: BC30201: Expression expected.
I've attached the screen shot
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

Rajiv AaryaAuthor Commented:
No I'm not using 2.0
Rajiv AaryaAuthor Commented:
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.
Rajiv AaryaAuthor Commented:
Okay.  Thank You!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.