1

I want to use a label value for a css class name.

I am getting a label value from database through Eval and want to use it for a css class name

Here is what I am doing

<span class="<asp:Label ID="lbl_icon" runat="server" Text='<%# Eval("icon")%>'></asp:Label>"></span>

but I'm not getting the result which i want.

1 Answer 1

2

There isn't any need to use a Label control there. You could just try the following:

<span class='<%# Eval("icon")%>'></span>
Sign up to request clarification or add additional context in comments.

3 Comments

Can i use label by the way ? Or if I can so how ?
@SaadSuri without being sure 100%, I think that you can't.
@SaadSuri - The Label control being rendered as a span element, you would end up with something like: <span class="<span>value</span>" ...></span>. It may work with a Literal control however, since it renders only its content (although Christos' answer is simpler). On the other hand, you could use a Label as your span element, setting its CssClassName with the Eval("icon") value.

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.