Consider the following code snippet:
<asp:TemplateField HeaderText="Item Data">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "ItemData1") %>
<br />
<%# DataBinder.Eval(Container.DataItem, "ItemData2") %>
</ItemTemplate>
</asp:TemplateField>
I need to refactor this so that if ItemData2 is blank, the <br />
does not render
I am unsure how I can achieve this.
EDIT: I tried to add a condition like so:
<% if(DataBinder.Eval(Container.DataItem, "ItemData2") != null) { %>
<br />
<%# DataBinder.Eval(Container.DataItem, "ItemData2") %>
<% } %>
It didn't work, and looks really ugly!
In DataBinder.Eval you can pass your condition like below and this will work for you.
<%#( DataBinder.Eval(Container.DataItem,"Item1)==null ?DataBinder.Eval(Container.DataItem,"Item1"):
DataBinder.Eval(Container.DataItem,"Item2"))%>