This is a migrated thread and some comments may be shown as answers.

Basic Filtering with RadListView

2 Answers 127 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Sergio
Top achievements
Rank 1
Sergio asked on 01 Apr 2011, 07:47 PM
Greetings

I am trying to create a basic filtering functionality similar to the found at the Demo documentation at http://demos.telerik.com/aspnet-ajax/listview/examples/filtering/defaultcs.aspx

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">
    <SelectParameters>
        <asp:Parameter Name="UserTable" />
    </SelectParameters>
</asp:ObjectDataSource>

  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;
        SelectCommand.Append(completeCommand.ToString());
        cmd.CommandText = SelectCommand.ToString();
 
        connection.Open();
        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.Clear();
                RadListViewFriendSelection.FilterExpressions.BuildExpression().Contains("Name", TextBoxFilter.Text.Trim()).Build();
                RadListViewFriendSelection.Rebind();
 
            }

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 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 07 Apr 2011, 09:06 AM
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.


Regards,
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
0
Sergio
Top achievements
Rank 1
answered on 07 Apr 2011, 11:05 PM
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. :-)
Tags
ListView
Asked by
Sergio
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Sergio
Top achievements
Rank 1
Share this question
or