I have the following code:
<asp:LinkButton runat="server"
CommandName="SwitchStep"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID")%>'
CssClass="<%# some conditional code here %> activestep">
Step <%# Container.ItemIndex + 1 %>: <%# DataBinder.Eval(Container.DataItem, "ID")%>
</asp:LinkButton>
Inline statements work in the CommandArgument attribute, and I know they work in the text attribute. For some reason, though, in the CssClass attribute, the inline statement ends up (unparsed) in the HTML output! What the hell?
In Chrome:
<a class="<%= 'steptab' %>" href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("StepControl:_ctl1:_ctl0", "", true, "", "", false, true))'>
Step 1: section_name</a>
Has anyone run into this before? I’m not sure why this shouldn’t work. It doesn’t seem logical, and I’m a little frustrated.
Some notes:
- If I put a character in here that doesn’t belong, such as “?” (this is VB), the compiler complains.
- Any server tag (<%, <%#, etc) shows up in the HTML.
- This is inside a repeater control. Wait, that’s in the code.
- If I remove the “activestep” class after the inline statement, the inline statement still appears, although at one time I didn’t have a class attribute appearing in HTML at all.
Any ideas? Thanks for your help!
I am not sure if you can write an Expression in
CssClassproperty. Try this:On the other hand, you could use
ItemDataBoundevent handler to wrapper your condition and set theCssClassproperty on the control inside your Repeater. Take a lookIn the WEbForm, add a reference to the ItemDataBound
VB.NET
C#