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?
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>
You could refactor it out to server side script.
<script runat="server">
protected string ShowIfEqual(RepeaterItem Item, string SomeValue) {
YourTypeThatIsDataBound _item = (YourTypeThatIsDataBound)Item.DataItem;
return _item.MyProperty == SomeValue ? _item.MyProperty : string.Empty;
}
</script>
And the call it inline as...
<%#ShowIfEqual(Container, "SomeValue")%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With