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

Get filtered DataSource after pressing search button

8 Answers 122 Views
SearchBox
This is a migrated thread and some comments may be shown as answers.
archimede
Top achievements
Rank 1
archimede asked on 25 Mar 2015, 02:34 PM
Good afternoon,

I'm working on a search box that filters the information from an EntityDataSource.
I am looking for a solution that gets you the "final" DataSource, I mean the data collection that you can read after putting some letters in the search box.

Is there any way to get it?

Thank you for your attention



8 Answers, 1 is accepted

Sort by
0
Aneliya Petkova
Telerik team
answered on 27 Mar 2015, 12:50 PM
Hi archimede,

You can use the OnSearch server side event which is raised when the search button is clicked, Enter is pressed or an item from the searchbox dropdown is  clicked. The event handler receives two parameters:
  1. The instance of the SearchBox firing the event
  2. An event arguments parameter that contains the following properties:
    • Text - returns the text that is typed in the searchBox, or the text of the selected result item.
    • Value - returns the value of the selected result item.
    • DataItem - returns the dataItem that is associated with the selected result item.
Then in the event handler you can filter the data source using the searched text and thus get the returned data collection.

Please check the following online example demonstrating similar scenario (you can do this also using EntityDataSource):
http://demos.telerik.com/aspnet-ajax/searchbox/examples/applicationscenarios/gridfilteredbysearchbox/defaultcs.aspx

Regards,
Aneliya Petkova
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
archimede
Top achievements
Rank 1
answered on 01 Apr 2015, 01:44 PM
Hello Aneliya,

thank you for your answer.
I tried to follow your example using the EntityDataSource but the DataItem is always null, so I can't have any information about my searching results.

Do you have any clue or other things I should add in order to retrieve the requested DataItem?

Thank you
0
archimede
Top achievements
Rank 1
answered on 01 Apr 2015, 02:12 PM
            <telerik:RadSearchBox runat="server" 
                ID="RadSearchBox1" 
                EmptyMessage="Cerca..."
                DataSourceID="EntityDataSource1" 
                DataValueField="IdHelp"
                DataTextField="DatiHelp" 
                DataKeyNames="DatiHelp, IdHelp"
                Width="300"
                EnableAutoComplete="true"
                OnClientSearch="lookForResults" 
                OnSearch="DisplayResults" >
                <DropDownSettings Height="400" Width="300" />
            </telerik:RadSearchBox>

    <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=DMWEntities"
            DefaultContainerName="DMWEntities" EntitySetName="Manuale_Machina" Select="it.[IdHelp], it.[DatiHelp], it.[Titolo]"
            AutoPage="true ">
    </asp:EntityDataSource>

 

I used this code in order to use RadSearchBox, if this can help. (I also tried the SQLDataSource, but it returns the same error)


0
Aneliya Petkova
Telerik team
answered on 03 Apr 2015, 09:43 AM
Hi archimede,

I can't see anything wrong with the code snippet you sent.
I made you a sample using EntityDataSource. Please try it and let me know if everything works ok at your side.

Regards,
Aneliya Petkova
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
archimede
Top achievements
Rank 1
answered on 22 Apr 2015, 10:49 AM

Hello,

 I tried your example and I have the same settings, for the EntityDataSource and for the object SearchBox, but I didn't get what I wanted.

Is there any possibility of retrieving the entire collection of DataItems that are showing while writing on the searchbox?

The scenario could be simulated in this way: I click on a single result and I get a DataItem, so I should click on all results to get the collection that I am looking for.

 

Thank you

0
Aneliya Petkova
Telerik team
answered on 23 Apr 2015, 08:07 AM
Hi archimede,

I am not sure I understand what exactly you need to achieve and why you want to get all the filtered data. But this it is not possible using RadSearchBox control. You can try some other controls - for example RadComboBox and see if it will be suitable for your scenario.

Regards,
Aneliya Petkova
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
n/a
Top achievements
Rank 1
Veteran
answered on 22 Jan 2021, 02:55 PM
Little disappointed in this example -- it is a cheat.  Not actually use EntityDataSource for the RadSearchBox
0
Vessy
Telerik team
answered on 26 Jan 2021, 08:55 AM

Hi Henry,

A sample on how to bind RadSearchBox with EntityDataSource is available in our documentation here:

https://docs.telerik.com/devtools/aspnet-ajax/controls/searchbox/data-binding/binding-to-asp-datasource-components#entitydatesource

<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=NorthwindEntities35"
    DefaultContainerName="NorthwindEntities35" EntitySetName="Customers" Select="it.[ContactName], it.[City], it.[ContactTitle]"
    AutoPage="true" OrderBy="it.[ContactName]">
</asp:EntityDataSource>
<telerik:RadSearchBox RenderMode="Lightweight" runat="server" ID="RadSearchBox3" EmptyMessage="Entity" DataSourceID="EntityDataSource1" DataValueField="ContactName" DataTextField="City"> <DropDownSettings Height="400" Width="300" /> </telerik:RadSearchBox>

Regards,
Vessy
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
SearchBox
Asked by
archimede
Top achievements
Rank 1
Answers by
Aneliya Petkova
Telerik team
archimede
Top achievements
Rank 1
n/a
Top achievements
Rank 1
Veteran
Vessy
Telerik team
Share this question
or