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

Avatar of undefined
Last Comment
Rajiv Aarya

8/22/2022 - Mon
Imran Javed Zia

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>
Rajiv Aarya

ASKER
Still getting an error in both the cases.
Compiler Error Message: BC30201: Expression expected.
I've attached the screen shot
err.jpg
ASKER CERTIFIED SOLUTION
Camillia

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
louisfr

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

Your help has saved me hundreds of hours of internet surfing.
fblack61
Rajiv Aarya

ASKER
No I'm not using 2.0
Rajiv Aarya

ASKER
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.?
Camillia

You get  the  value  of  order created field  from database or server side...no? If so...it should be server side.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Rajiv Aarya

ASKER
Okay.  Thank You!