tags:

views:

250

answers:

1

Inside a repeater's ItemTemplate there is a:

<tr class="class1">

</tr>

I want this class to be changed to "class2" according to a valu that is bounded to this repeater, Eval("Locked").

If locked==true class="class1" else class="class2", how can I do it in simple way?
(in code behind it's to complex)

+5  A: 

Really simple, just put a serverside tag:

<asp:Repeater ID="yourRepeater" runat="server">
    <ItemTemplate>
        ....
        <tr class='<%# Convert.ToBoolean(Eval("Locked")) ? "class1" : "class2" %>'>
            ....
        </tr>
        ....
    </ItemTemplate>
</asp:Repeater>

UPDATE: Thanks Kobi, i've missed Convert.ToBoolean() :)

tanathos
Does that compile? Shouldn't that be `"true".Equals(...)`? IIRC, eval returns an object.
Kobi
You're right, I've missed the convertion.
tanathos