Edit this page

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

Is this article helpful? No Yes
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article