Question

I'm working on a small problem where I'm trying to show/hide a panel based on two criteria

  1. A specific data field must not be blank
  2. The specific data filed must also not equal "Not Relocatable"

Unfortunately this doesn't seem to be working for me (note that setting either one or the other criteria works just fine.)

        <asp:Panel runat="server" Visible='<%#If(Not String.IsNullOrEmpty(DataBinder.Eval(Container.DataItem, "_236")) Or Not DataBinder.Eval(Container.DataItem, "_236") = "Not Relocatable", True, False)%>'>
        <tr>
            <td>
            </td>
            <td class="align-right lightgreen">
                Buyer would consider relocating a business, if it is:
            </td>
            <td>
            </td>
            <td colspan="3">
                <%#DataBinder.Eval(Container.DataItem, "_236")%>
            </td>
            <td>
            </td>
        </tr>
        </asp:Panel>

Can anyone lend a hand to rectify this problem for me?

Was it helpful?

Solution

The syntax <%# %> is a data binding syntax, not an inline expression syntax. You cannot use procedural code inside of it like you can in the inline code <% %> tags.

Data binding tags must contain a single Eval or Bind function. If you need to do conditional branching based on those functions, you will need to do it using inline code around the binding tags.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top