mori
mori

Reputation: 40

Asp.net Telerik Radsearchbox not filter properly

I'm using radsearchbox as a control in my site for search trough db. I used a object data source as radsearchbox's datasource. the aspx code is here:

  <telerik:RadSearchBox ID="RadSearchBox1" runat="server" 
    DataSourceID="ObjectDataSourceSearch" 
    DataTextField="Name" DataValueField="ID" 
   EmptyMessage="search here" 
     Skin="Silk" MinFilterLength="3">
  </telerik:RadSearchBox>

  <asp:ObjectDataSource ID="ObjectDataSourceSearch" runat="server" 
    SelectMethod="detail" TypeName="InStore">
  </asp:ObjectDataSource>

And detail function is:

 Function detail() As List(Of info)
    Dim All_info As New List(Of info)
      Dim _inf As New info
            _inf.ID = 1
            _inf.Name = "aaa"
             All_info.Add(_inf)
    Dim _inf2 As New info
    _inf2.ID = 100
   _inf2.Name = "bbb"
    All_info.Add(_inf2)
     Return All_info
End Function

And when I typed any text in radsearchbox, It displays all items in the list.("aaa" and "bbb") why???

Upvotes: 1

Views: 435

Answers (1)

Balaji
Balaji

Reputation: 1515

Yes. it will display everything in the list, because in SelectMethod you are setting the function detail(). The function detail is returning the whole list.

To overcome this you can use the OnSearch event handler of the radseachbox or simply use the Linq to filter the result and then return the filtered list.

I don't know about your scenario, but this is my guess. try this code

Protected Function Search(sender As Object, e As SearchBoxEventArgs) As List(Of info)
    Dim searchtext As String = e.text
    Dim filteredinfo As New List(Of info)()
    Dim searchresult As New List(Of info)()
    filteredinfo = detail()
    searchresult = filteredinfo.where(Function(res) res.Contains(searchtext))
    searchresult += filteredinfo.where(Function(res1) res1.Contains(searchtext))
    Return searchresult
End Function

And dont forgot to paste this code in OnSearch event handler of radsearchbox.

Upvotes: 1

Related Questions