filtering results in listview by column name

Posted on 2011-05-08
Last Modified: 2012-06-21
HOw can I filter results in a listview control. I have 5 boolean fields that I would like to show in a drop down and filter on those columns. please help thanks
Question by:TrialUser
    LVL 1

    Expert Comment

    you can use the
    Selected Index change
    property of
    your Dropdown

    and In the select Query
    pass the id or the filter
    option you want

    and with selected index changed
    event of Dropdown
    Fill the Listview

    try this..will work
    LVL 83

    Expert Comment

    More description please. What 5 fields? What columns are shown in Listview? How are you accessing data? Using AccessDataSource/SqlDataSource?

    Author Comment

    I call a SQL Server stored procedure to return data. I bind the Dataset.tables(0) to the listview on Page Load.

    I have some boolean fields like : IsRecyclable, IsGreen, IsFreeShippable and so on.
    I would like to have a drop down for these boolean fields like :
    Show All, Only Green, Only ISFreeShippable = true

    So is there anything inbuilt in asp:listview that I could take advantage of? Or should I have a drop down and on Selected Indiex change fetch data again from SQL and bind it? Please help thanks

    LVL 83

    Accepted Solution

    You can apply the filter on the DataTable.


    If DDL.Text = "Show All" Then
       dSet.Tables(0).DefaultView.RowFilter = ""
    ElseIf DDL.Text = "Only Green" Then
       dSet.Tables(0).DefaultView.RowFilter = "IsGreen=True"
    ElseIf ...
    End If
    Listview1.DataSource = dSet.Tables(0).DefaultView

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now