ANP
ANP

Reputation: 15607

Hide items from a ListView control

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

Answers (5)

이은성
이은성

Reputation: 1

Set the width property to 0 in the listview item.

enter image description here

Upvotes: 0

Lê Bảo Lộc
Lê Bảo Lộc

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

David
David

Reputation: 73564

Options include:

  • If you're talking about hiding an entire item in the list... Writing your query so those items are filtered out when you get the list that your ListView is bound to. (i.e. add a WHERE clause to the SELECT statement if these are coming from the DB.)
  • If you're talking about specific controls within an ItemTemplate in your ListViews, you can set the "Visible=false" in places where you want it hidden.

like so:

<ItemTemplate>
   <asp:Button Runat = "Server" visible="<%# Eval(SomeCondition) %>" Text = "Click Me" />
</ItemTemplate>

Upvotes: 0

Lloyd
Lloyd

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

Lucas B
Lucas B

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

Related Questions