SearchContext with 2 differents datasource

5 posts, 0 answers
  1. Simon
    Simon avatar
    12 posts
    Member since:
    Nov 2014

    Posted 03 Feb 2015 Link to this post

    Hi guys, I've been struggling with a problem all day.

    The scenario I want to acheive is:
    With the same radsearchbox, I wanna search in 2 differents datasource.

    Let me explain. On my main page, if I choose the "News" context, I wanna be able to search in my News database on 3 differents fields.
    I was able to get the expected result with this code.

    <telerik:RadSearchBox ID="rsbSearch" runat="server" InputType="Text" TextSettings-SelectionMode="Single" DataSourceID="SqlSearchDataSource"
                                        DataValueField="ID" OnDataSourceSelect="rsbSearch_DataSourceSelect" EmptyMessage="Rechercher" Width="250px" MaxResultCount="5" >
                                        <SearchContext ShowDefaultItem="false" DataKeyField="Titre" >
                                                <telerik:SearchContextItem Text="Nouvelle" Key="News" />
                                                <telerik:SearchContextItem Text="Bottin" Key="Bottin" />
                                        <DropDownSettings CssClass="rsbSearchPopUp">
                                                <asp:PlaceHolder ID="test1" runat="server">
                                                    <table class="tableNews" style="z-index:200;" >
                                                                <td class="actualityDescription">

    and the code behind
    protected void rsbSearch_DataSourceSelect(object sender, SearchBoxDataSourceSelectEventArgs e)
                SqlDataSource source = (SqlDataSource)e.DataSource;
                RadSearchBox mySearchBox = (RadSearchBox)sender;
                string filterString = e.FilterString;
                if (e.SelectedContextItem != null && e.SelectedContextItem.Key.ToLower() == "news")
                    source.SelectCommand = "SELECT TOP 100 * FROM [NewsData] WHERE DescriptionCourte Like '%" + filterString + "%'" +
                        " OR Titre Like '%" + filterString + "%'" +
                        " OR DescriptionLongue Like '%" + filterString + "%'";
                else {
                    //mySearchBox.DataSource = Intranet.BL.Employe.GetEmployees(true, filterString);

    Now by choosing the "Bottin" context, I wanna be able to get the result from a business logic object named Employe from a function GetEmployeList(string name). I tried to set the new datasource of my searchbox with the result of my function, but it didn't work since i already define a datasourceID

    Any hints on how I could be able to have 2 different datasource depending on the context choice?

    Thank you.
  2. Simon
    Simon avatar
    12 posts
    Member since:
    Nov 2014

    Posted 03 Feb 2015 Link to this post

    I wanna be able to choose a different ItemTemplate too according to the choosen context, however, I don't have any ItemBound event that i could attach....

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Nencho
    Nencho avatar
    1458 posts

    Posted 06 Feb 2015 Link to this post

    Hello Simon,

    i am afraid that you cannot change the DataSource control dynamically. However, I would suggest you to use a StoredProcedure to supply the SearchBox with data. Thus, you can pass the selected item from the
    SearchContext as a parameter for the procedure and return the data from the corresponding table.

    As for the change of the template - I am afraid that currently this is not applicable, since there is no event to handle the change of the selection in the ContextMenu. However, I have already forwarded this to our developer team, as a feature request. In addition, I have updated your Telerik Points for pointing that out.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  5. Simon
    Simon avatar
    12 posts
    Member since:
    Nov 2014

    Posted 06 Feb 2015 in reply to Nencho Link to this post

    Thank you, I'll use a stored proc. 

    As for the Itemtemplate, I found a work around for the moment.

    Many thanks.

  6. roy
    roy avatar
    8 posts
    Member since:
    Mar 2011

    Posted 12 Jun in reply to Simon Link to this post

    Hey Simon i know this is an old post but do you think you can post the work around you found for dynamic templates?



Back to Top
UI for ASP.NET Ajax is Ready for VS 2017