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

[Solved] Load on demand with a defined data source?

1 Answer 219 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Chris May
Top achievements
Rank 1
Chris May asked on 01 Feb 2010, 10:34 PM
The load on demand example has the developer creating RadComboBoxItem objects and add those to the RadComboBox items collection.

Is there any way to work with Load on Demand in conjunction with the defined datasource model, where I have a datasource on my page that is fetching the objects for the radcombobox, or do I have to manually create RadComboBoxItems in order to use Load On Demand?

1 Answer, 1 is accepted

Sort by
0
Kalina
Telerik team
answered on 04 Feb 2010, 03:47 PM
Hi Chris May,

There is one approach to use LoadOnDemand and a DataSource defined on page.

At ItemsRequested event of RadComboBox you can set DataSourceID, DataTextField and DataValueField properties of the RadComboBox. The SelectCommand property of the DataSource has to be set too, and then manually call DataBind method.

<telerik:RadComboBox ID="combo" runat="server"
    EnableLoadOnDemand="true"OnItemsRequested="Combo_OnItemsRequested">
    <ItemTemplate>
        <%# DataBinder.Eval(Container, "Text")%>
    </ItemTemplate>
</telerik:RadComboBox>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString1 %>" >
</asp:SqlDataSource>

protected void Combo_OnItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    this.SqlDataSource1.SelectCommand =
        "SELECT TOP 1000 [LocationID],[Name]FROM [AdventureWorks].[Production].[Location] WHERE [Name] LIKE '" + e.Text + "%'";
    this.combo.DataSourceID = this.SqlDataSource1.ID;
    this.combo.DataTextField = "Name";
    this.combo.DataValueField = "LocationID";
    this.combo.DataBind();
}

All the best,
Kalina
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
ComboBox
Asked by
Chris May
Top achievements
Rank 1
Answers by
Kalina
Telerik team
Share this question
or