Reputation: 15607
I am using a listview to display some items.But sometimes based on condition I have to hide few items from the list.So how can I do this?I am using ASP.Net with c#.
Upvotes: 0
Views: 9700
Reputation: 11
I've just found a solution to solve this problem, using ItemsContainerStyle:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Visibility" Value="{Binding propertyName, Converter={StaticResource ITVConverter}}"/>
</Style>
</ListView.ItemContainerStyle>
Upvotes: 1
Reputation: 73564
Options include:
like so:
<ItemTemplate>
<asp:Button Runat = "Server" visible="<%# Eval(SomeCondition) %>" Text = "Click Me" />
</ItemTemplate>
Upvotes: 0
Reputation: 1403
If your list items are dynamically populated, I would check for the condition, and then chance the DataSourceID, or the query that the datasource uses and then
MyListView.DataBind();
Otherwise, if it is not dynamically populated, you could define the ListItems as static members of that page, then check for your condition and remove the items that you want to "hide" before you add the ListItems collection to the ListView.
Upvotes: 0
Reputation: 12013
There is no way to "hide." You will have to remove and then add when you want the item to be visible again.
Upvotes: 1