tags:

views:

127

answers:

1

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?

A: 

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.

Dan Story
I need to be able to evaluate databound content. How would I do this without using data binding syntax?
rockinthesixstring
also, this bit works just fine `<asp:Panel runat="server" Visible='<%#If(Not String.IsNullOrEmpty(DataBinder.Eval(Container.DataItem, "_236"), True, False)%>'>`
rockinthesixstring
You need to change your boolean OR to an AND between the two clauses in the If() statement. Right now your statement is, "if the item isn't blank *or* if it isn't 'not relocatable', display the panel." If the item is non-blank and equals "not relocatable", it will meet the first condition and the second will be irrelevant.
Dan Story
Ah, good point. Thanks... such a stupid mistake.
rockinthesixstring
Funny how a second pair of eyes can make all the difference. I've made plenty of errors like that myself.
Dan Story