5

I read this document http://support.microsoft.com/kb/976112 where explains all the embedded code blocks available but I want to combine two of them.

I want to use base <% ... %> embedded code blocks with <%# ... %> data-binding expression

Example I want to add an "If" condition to this code:

<asp:Label ID="lblHello" runat="server" Text="<%# DataBinder.Eval(Container.DataItem, "[\"Txt\"]")%>"></asp:Label>

Regards.

1 Answer 1

5

The difference in the <% and <%# is mainly in when they're run (the former at render time, the latter at data binding). As such, it makes no sense to "combine" them.

What you likely want to do, is to run some additional code when data binding to do your if statement. If it's a simple expression, you can just inline it:

<%# MyProperty ? Eval("Txt") : Eval("OtherTxt") %>

If it's more complicated, then it's usually best to just call a code-behind method to do it for you:

<%# MyMethod(Eval("Txt")) %>

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

Comments

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.