feronovak
feronovak

Reputation: 2697

Conditions within .aspx file for ListView ItemTemplate

Is there a way to filter <%Eval("value") %> within ASPX file?

 <ItemTemplate>
     <tr class='<%# Container.DataItemIndex % 2 == 0 ? "row" : "row alt" %>'>
        <td class="width-200"><%#Eval("znacka") %></td>
        <td class="width-200"><%#Eval("status") %></td>
        <td><asp:LinkButton ID="btnZnackyDelete" runat="server" Text="delete" CommandName="Delete" /></td>
     </tr>
 </ItemTemplate>

I want to show linkbutton only if Eval("status") == 0

is it possible within aspx file? Or how do you specify this within c# code?

Upvotes: 1

Views: 1992

Answers (2)

Tim Schmelter
Tim Schmelter

Reputation: 460138

This should work:

<asp:LinkButton ID="btnZnackyDelete" Visible='<%# Convert.ToBoolean(Eval("status").ToString() == "0") %>' runat="server" Text="delete" CommandName="Delete" />

Upvotes: 3

Chad Ruppert
Chad Ruppert

Reputation: 3680

Use an if statement, that's easiest.

<% if (Eval("value") == 0) { %>
<asp:LinkButton ID="btnZnackyDelete" runat="server" Text="delete" CommandName="Delete" />
<% } %>

You can also handle the OnItemDataBound event for the repeater or whatever you are using. In that you can use findcontrol and toggle visibility.

If is by far easier though.

Upvotes: 0

Related Questions