New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Server-side Binding

SearchContext can be easily bound declaratively to some DataSource by setting DatasourceID, DataTextField and DataKeyField properties to the desired fields so that the DataKeyField is the same as the one set to DataContextKeyField of Searchbox control.In server side bindingImageUrl property can be assigned to the SearchContextItem in the ItemDataBound of SearchContext as it is achieved in the code below:

<telerik:RadSearchBox RenderMode="Lightweight" ID="RadSearchBox3" runat="server" Width="500" DataSourceID="SqlDataSource3" 
        DataTextField="LastName" DataValueField="FirstName" DataContextKeyField="EmployeeID" >
    <SearchContext DataSourceID="SqlDataSource3" DataTextField="City" DataKeyField="EmployeeID">
<asp:SqlDataSource ID="SqlDataSource3" runat="server" 
    ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="SELECT [LastName], [FirstName], [EmployeeID],[City], [PhotoPath] FROM [Employees]" >

protected void Page_Load(object sender, EventArgs e)
    RadSearchBox3.SearchContext.ItemDataBound += SearchContext_ItemDataBound;

void SearchContext_ItemDataBound(object sender, SearchBoxContextItemEventArgs e)
    e.Item.ImageUrl = ((DataRowView)e.Item.DataItem)["PhotoPath"].ToString();

Protected Sub Page_Load(sender As Object, e As EventArgs)
    RadSearchBox3.SearchContext.ItemDataBound += SearchContext_ItemDataBound
End Sub

Private Sub SearchContext_ItemDataBound(sender As Object, e As SearchBoxContextItemEventArgs)
    e.Item.ImageUrl = DirectCast(e.Item.DataItem, DataRowView)("PhotoPath").ToString()

End Sub

In this article
Not finding the help you need? Improve this article