asp.netasp.net-2.0repeater

Testing a Container.DataItem with inline code


I would like to do something like this in ASP.Net 2.0:

 <asp:Repeater id="myRepeater" runat="server">
      <ItemTemplate>
           <% if (DataBinder.Eval(Container.DataItem, "MyProperty").Equals("SomeValue")) { %>
                <%#DataBinder.Eval(Container.DataItem, "MyProperty")%>
           <% } %>
      </ItemTemplate>
 </asp:Repeater>

But I cannot test the DataBinder.Eval(Container.DataItem, "MyProperty") like this.

NOTE: I don't have access to the source code, I can only change the aspx inline.

NOTE2: I know I can use this:

 <%#DataBinder.Eval(Container.DataItem, "MyProperty").Equals("SomeValue")?"<!--":""%>

but I was looking for a cleaner way.

Is there a way to test the Container.DataItem with inline code inside a Repeater?


Solution

  • I would do this. You bind your "visibility" function to the visible property of an asp:literal control:

    <asp:Repeater id="myRepeater" runat="server">
        <ItemTemplate>
            <asp:literal runat='server' id='mycontrol' 
              visible='<%# DataBinder.Eval(Container.DataItem, "MyProperty").Equals("SomeValue") %>'>
              <%# DataBinder.Eval(Container.DataItem, "MyProperty") %>
            </asp:literal>
         </ItemTemplate>
     </asp:Repeater>