Eldila
Eldila

Reputation: 15756

Using Eval inside a IF statement and Repeater

I am trying to use Eval inside a IF Statement and Repeater.

I want to do something like this:

 <asp:Repeater runat="server" ID="rpRepeater">
      <ItemTemplate>
           <% if ((bool)Eval("A_Boolean"))
              { %>
                blah...
           <% } %>
      </ItemTemplate>
 </asp:Repeater>

This code gives me the following error:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Upvotes: 1

Views: 2759

Answers (2)

Knaģis
Knaģis

Reputation: 21495

It is possible to simulate if statements like this (code goes within ItemTemplate).

<asp:Panel runat="server" Visible='<%# Eval("A_Boolean") %>'>
    blah...
</asp:Panel>

Upvotes: 1

Andrija
Andrija

Reputation: 14493

Eval can be only used inside "binding" tag.

<%# Eval("A_Boolean") %>

http://support.microsoft.com/kb/307860#1a

Upvotes: 1

Related Questions