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

ListView Filtering Always Returns No results

1 Answer 83 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 2
Veteran
Chris asked on 21 Mar 2016, 01:16 PM

I have not been able to figure out why I am not getting the filter results I am expecting. In fact I always get no results.

When the page first loads all the data is displayed as expected.

When I enter as search query and click the Search button the RadListView control refreshes with no results. I see the spinner so I know it posted back via AJAX.

I debug the C# code and I can confirm that the search query value is passed to the BuildExpression for the filter. No errors or exceptions are thrown.

If I submit an empty query it should just Clear the Filter and all results should show, but that does not happen.

The datasource is a List<DeviceSearchResult>.

Any ideas?

Here is my markup:

<asp:Panel ID="pnlSearchView" runat="server" Visible="True">
    <h1>Search View</h1>
     
    <telerik:RadAjaxManager ID="RadAjaxManager" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="txtDeviceSearchQuerySubmit">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="lvDeviceSearchResults" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
       <asp:TextBox ID="txtDeviceSearchQuery" runat="server"></asp:TextBox>
    <asp:Button ID="txtDeviceSearchQuerySubmit" runat="server" OnClick="txtDeviceSearchQuerySubmit_OnClick" Text="SEARCH"/>
    <telerik:RadListView ID="lvDeviceSearchResults" RenderMode="Lightweight" runat="server"
         OnNeedDataSource="lvDeviceSearchResults_NeedDataSource"
         ItemPlaceholderID="phDeviceSearchResult">
        <LayoutTemplate>
            <asp:PlaceHolder ID="phDeviceSearchResult" runat="server"></asp:PlaceHolder>
        </LayoutTemplate>
        <ItemTemplate>
            <%# ShowGroupRow(Eval("DeviceManufacturer").ToString())=="yes"
                    ? "<div class=\"manufacturer\"><strong>"+Eval("DeviceManufacturer")+"</strong></div>"
                    : ""  %>
            <div>- <%# Eval("DeviceName") %> | <%# Eval("DevicePackage") %> | <%# Eval("DevicePin") %></div>
            <asp:ListView ID="lvDeviceSearchResultAdapters" runat="server" ItemPlaceholderID="phDeviceSearchResultAdapters" DataSource='<%# Eval("DeviceAdapters") %>'>
                <LayoutTemplate>
                    <ul><asp:PlaceHolder ID="phDeviceSearchResultAdapters" runat="server"/></ul>
                </LayoutTemplate>
                <ItemTemplate>
                    <li><%# Container.DataItem.ToString() %></li>
                </ItemTemplate>
            </asp:ListView>
        </ItemTemplate>
    </telerik:RadListView>
</asp:Panel>

 

Here is my C#:

protected void lvDeviceSearchResults_NeedDataSource(object sender, RadListViewNeedDataSourceEventArgs e)
{
    lvDeviceSearchResults.DataSource = TempDeviceSearchResults.OrderBy(d => d.DeviceManufacturer).ThenBy(d =>d.DeviceName);
}
 
protected void txtDeviceSearchQuerySubmit_OnClick(object sender, EventArgs e)
{
    lvDeviceSearchResults.FilterExpressions.Clear();
    var query = txtDeviceSearchQuery.Text.Trim();
    if (!string.IsNullOrEmpty(query))
    {
        lvDeviceSearchResults.FilterExpressions.BuildExpression(ex => ex
            .Contains("DeviceName", query)
            );
    }
    lvDeviceSearchResults.Rebind();
}

1 Answer, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 2
Veteran
answered on 22 Mar 2016, 10:06 AM
I found the problems. There were actually a few and none to do with the code above. One issue was with the use of the RadAjaxManager and DNN (I did not need to use it). The other was with the use of RadAutoCompleteBox. I was just using the .Text property of the control which included a semi-colon ";" at the end of the entered text which I missed during debugging.
Tags
ListView
Asked by
Chris
Top achievements
Rank 2
Veteran
Answers by
Chris
Top achievements
Rank 2
Veteran
Share this question
or