japesu
japesu

Reputation: 134

VB .NET XDocument and using IIF

I've just got to know XDocument in VB .NET and really like the way I can write XML documents in my code but have just one little problem I can't find a good solution for. The problem is with IIF that I use to check some conditions for example if a node should be printed or not.

The problem is when I want to print multiple nodes (from a list of strings) if my conditions are true first. Here is the problem code where I'm checking few conditions and in true part I'll try to loop nodes:

<%= IIf(settings.UseInvoiceFreeText _
OrElse settings.BuyerIntermediatorCode = "" _
OrElse settings.BuyerIntermediatorCode = "", _
      <%= From freeText As String In InvoiceFreeTexts
       Select <InvoiceFreeText><%= freeText %></InvoiceFreeText>
       %>, _
       Nothing)
%>

The error message says: An embedded expression cannot be used here.

How should I do this?

Thank you :)

Upvotes: 3

Views: 351

Answers (1)

Gideon Engelberth
Gideon Engelberth

Reputation: 6155

The error is pointing out that you are already in an expression. You can put your query inside standard parentheses () instead of the expression embedding <%= %>.

Also, use the If() operator instead of IIf() function so you do not always evaluate both branches.

Upvotes: 2

Related Questions