Reputation: 4366
I seen similar questions asked various places, but haven't really found an answer to this that works for me yet. Basically, I have a ListView where I want to hide table rows if a particular value in the data binding if a particular condition is true (most often if the value of the item is null or empty string). I've tried making the tr runat="server" and setting the condition on the visible property, but this returns a runtime error "The server tag is not well formed." Here's what I'm trying to do:
<asp:ListView runat="server" ID="FullInfoListView">
<LayoutTemplate>
<table class="tablestripe" width="100%">
<asp:Placeholder runat="server" ID="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr valign="top" class="eventrow1">
<td colspan="2">
<h3><%# Eval("FirstName") Eval("LastName") %></h3>
</td>
</tr>
<tr valign="top" runat="server" Visible="<%# (bool)Eval("PhotoVis") %>">
<td colspan="2">
<img src="~/Userphoto/thumb/<%# Eval("NetworkLogin") %>.jpg" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
Upvotes: 0
Views: 4783
Reputation: 21117
You have to have single quotes around the Visible
setter:
<tr valign="top" runat="server" Visible='<%# (bool)Eval("PhotoVis") %>'>
<td colspan="2">
<img src='~/Userphoto/thumb/<%# Eval("NetworkLogin") %>.jpg' />
</td>
</tr>
Upvotes: 6
Reputation: 46047
You could wrap the row in a PlaceHolder
:
<asp:PlaceHolder ID="PlaceHolder1" runat="server" Visible='<%# (bool)Eval("PhotoVis") %>'>
<tr valign="top">
<td colspan="2">
<img src='~/Userphoto/thumb/<%# Eval("NetworkLogin") %>.jpg' />
</td>
</tr>
</asp:PlaceHolder>
EDIT: Included single quotes around image src
attribute
Upvotes: 1