Within an ASP.NET user control I have the line:
<div>Web: <a href="<%# Eval("Web") %>"><%# Eval("Web") %></a></div>
I’d like to change it so this HTML is only rendered if Web has a value.
I’ve tried wrapping String.IsNullOrEmpty(Eval("Web") as string) in server side script but Eval can only be used inside a “binding” tag.
What is the best way to do this?
It’s a bit of a workaround, but you could have a hidden field in your ItemTemplate tag:
You could then set the ‘runat’ attribute of the div to ‘server’ and give the div an ID.
In your code-behind, you check whether or not
HiddenField1is empty. If it’s not empty, then set ‘divWeb’visible = true.The downside to this method is that the user could manually change the HiddenField1 value. However, if that’s not a problem (security wise), then you could try this method.
Update
The code snippet below is from the inline section of this site:
There are also alternative options in this thread