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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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>


or

<span class="order_in_status" style='display:<%# Convert.ToInt32(Eval("OrderCreated"))  == 1 ? "block !important;" : "none !important;" %>'></span>
0
Rajiv AaryaAuthor Commented:
Still getting an error in both the cases.
Compiler Error Message: BC30201: Expression expected.
I've attached the screen shot
err.jpg
0
CamilliaCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

louisfrCommented:
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

0
Rajiv AaryaAuthor Commented:
No I'm not using 2.0
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.?
0
CamilliaCommented:
You get  the  value  of  order created field  from database or server side...no? If so...it should be server side.
0
Rajiv AaryaAuthor Commented:
Okay.  Thank You!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.