3

Simple question and no answer somehwere ... What's wrong?

ASP.NET example:

<asp:Repeater ID="myRepeater" runat="server">
    <ItemTemplate>
        <% if(!string.IsNullOrWhiteSpace(((Message)((RepeaterItem)Eval("Container")).DataItem).text)) <%-- <- Exception --%>
           { %>
        <div class="msg">
            <%# ((Message)Container.DataItem).text %> <%-- <- This works fine! --%>
        </div>
        <% } %>
    </ItemTemplate>
</asp:Repeater>

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

I don't understand why this is not working >.<

Thanks in Advance for ideas or informations.

Patrick
  • 829
  • 2
  • 13
  • 34
  • 1
    please check this http://stackoverflow.com/questions/2571545/databinding-methods-such-as-eval-xpath-and-bind-can-only-be-used-in-the – Ashley John Jun 28 '16 at 10:57

1 Answers1

2

you can use this code

<asp:Repeater ID="myRepeater" runat="server">
    <ItemTemplate>
        <div runat="server" visible='<%# !string.IsNullOrWhiteSpace(((Message)((RepeaterItem)Eval("Container")).DataItem).text)%>'
            <div class="msg">
                <%# ((Message)Container.DataItem).text %>
            </div>
        </div>
</ItemTemplate>

Kahbazi
  • 14,331
  • 3
  • 45
  • 76