Basic Filtering with RadListView

3 posts, 0 answers
  1. Sergio
    Sergio avatar
    30 posts
    Member since:
    Jul 2010

    Posted 01 Apr 2011 Link to this post


    I am trying to create a basic filtering functionality similar to the found at the Demo documentation at

    The only distinction is that my application uses ObjectDataSource to bind  the RadListView control. Here is a brief about the ObjectDataSource

    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" TypeName="FriendBarDataSet"
        SelectMethod="GetFriends" OnSelecting="ObjectDataSource1_Selecting">
            <asp:Parameter Name="UserTable" />

      protected void ObjectDataSource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
            e.InputParameters["UserTable"] = UserTable;
    /// And in the FriendBarDataSet Class
    public SQLiteDataReader GetFriends(string UserTable)
            SQLiteConnection connection = new SQLiteConnection(WebConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString);
            SQLiteCommand cmd = new SQLiteCommand();
            cmd.Connection = connection;
            StringBuilder SelectCommand = new StringBuilder();
            string Table = "[" + UserTable.ToString() + "]";
            string SQL = "SELECT [ID], [uid], [Name], [sex], [birthday_date] FROM ";
            string completeCommand = SQL + Table;
            cmd.CommandText = SelectCommand.ToString();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);

    The ListView Binds with No Problem. It is doing what it Suppose to do..

    However, when in try to implement a filter similar to the demo one, the filter is not functional and it throws me an error. Here is how i go about Implementing the filter..

    if (!String.IsNullOrEmpty(TextBoxFilter.Text))
                    RadListViewFriendSelection.FilterExpressions.BuildExpression().Contains("Name", TextBoxFilter.Text.Trim()).Build();

    The filer is throwing me the following exception::

    System.InvalidOperationException: DataReader has been closed @ RadListViewFriendSelection.Rebind()

    Could you help me implement a simple filter into this application? To filter - The "Name" field of the ListView control using "Contains". notice that I am accessing an SQLite data. I don't know if this happen to influence. In which case, I will be open to suggestions of implementing filtering in a different way.

    Thank you for your help.

  2. Maria Ilieva
    Maria Ilieva avatar
    4017 posts

    Posted 07 Apr 2011 Link to this post

    Hi Sergio,

    Note that when a Data Reader is used the data will be read only once and you could not manipulate them including filtering them and setting a filter expression. Therefore in this case I would suggest you to add the data form the data source in a DataTable and verify if this works for you.

    Maria Ilieva
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Sergio
    Sergio avatar
    30 posts
    Member since:
    Jul 2010

    Posted 07 Apr 2011 Link to this post

    Thanks Maria

    The Filtering functionality of the RadListView I believe uses the Dataview.RowFilter property to filter the rows.

    As a result, simarly to ObjectDataSources, the data source needs to be represented by a DataSet, a DataTable, or a DataView Object.

    So instead of having my datasource return a SQLiteDataReader, I changed so it returned a DataTable and problem solve. Thought about including this for future references. :-)
Back to Top