5

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)

1 Answer 1

7

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() :)

Sign up to request clarification or add additional context in comments.

1 Comment

Does that compile? Shouldn't that be "true".Equals(...)? IIRC, eval returns an object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.