The Default Item in a RadComboBox facilitates custom validation scenarios. The DefaultItem will appear as the first item in the drop down even if there are no items.

tip

The DefaultItem feature is available for read-only combo boxes (i.e., AllowCustomText must be set to false, its default value). For load-on-demand scenarios, see the Default Item with Load On Demand section below.

When the default item is selected, the value of the RadComboBox DOM object will return default item's value, in order to validate easier with the required fields validators (see the examples below). The server/client side Text property of the RadCombobox will return the default item text.

The Default Item will not persist in the server/client side RadComboBoxItem's collection. The server/client side SelectedIndexChanged events will not be fired when the default item is selected. In addition, ItemTemplates do not affect the DefaultItem and you could not rely on the ViewState.

Always add the desired item at the top of the items list that your load-on-demand logic will return. This can depend on the Text value from the combo box that the handler receives. For example, if it is an empty string, add a default item, otherwise, return only relevant data and/or a default item.

If you are using custom templates, this will let the default item also use that template. The other two options can only provide standard text-value items.

You can use the OnClientLoad event to create an item with the desired values so it will always be at the top of the list and item from load-on-demand requests will be appended after it. You must set the AppendDataBoundItems property to true.

Declarative data source

<telerik:RadComboBox ID="RadComboBox1"
RenderMode="Lightweight"
runat="server"
AllowCustomText="True"
EnableLoadOnDemand="true"
OnClientLoad="OnClientLoad"
AppendDataBoundItems="True"
DataSourceID="SqlDataSource1"
DataTextField="CompanyName"
DataValueField="CompanyName">
</telerik:RadComboBox>
<script>
function OnClientLoad(combo, args) {
//the two commented calls store the item in the ClientState of the control so it will get persisted across postbacks
//and it is easier to just add it each time the combo initialized than to check if it is there every time
//combo.trackChanges();
var comboItem = new Telerik.Web.UI.RadComboBoxItem();
comboItem.set_text("Default Option");
comboItem.set_value("-1");
var items = combo.get_items();
items.insert(0, comboItem);
//combo.commitChanges();
}
</script>
<asp:SqlDataSource runat="server" ID="SqlDataSource1"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT [CompanyName] from [Customers] ORDER By [CompanyName]">
</asp:SqlDataSource>

ItemSrequested handler

<telerik:RadComboBox ID="RadComboBox2"
RenderMode="Lightweight"
runat="server"
AllowCustomText="True"
EnableLoadOnDemand="true"
OnClientLoad="OnClientLoad"
AppendDataBoundItems="True"
OnItemsRequested="RadComboBox2_ItemsRequested"
OnClientDropDownOpening="requestItems">
</telerik:RadComboBox>
<script>
function OnClientLoad(combo, args) {
//the two commented calls store the item in the ClientState of the control so it will get persisted across postbacks
//and it is easier to just add it each time the combo initialized than to check if it is there every time
//combo.trackChanges();
var comboItem = new Telerik.Web.UI.RadComboBoxItem();
comboItem.set_text("Default Option");
comboItem.set_value("-1");
var items = combo.get_items();
items.insert(0, comboItem);
//combo.commitChanges();
}
function requestItems(sender, args) {
sender.requestItems("", true);//request items each time
//you can add a flag to prevent this from running multiple times
//or use the server EndOfItems flag
}
</script>

Protected Sub RadComboBox2_ItemsRequested(sender As Object, e As RadComboBoxItemsRequestedEventArgs)
For i As Integer = 0 To 4
RadComboBox2.Items.Add(New RadComboBoxItem(i.ToString(), i.ToString()))
'set to true when data is finished to prevent further requests
e.EndOfItems = True
Next
End Sub

With the AppendDataBoundItems property to true, such an item will appear at the top of each batch of items returned from the data source. This means it may appear multiple times in the dropdown, depending on the exact load-on-demand scenario, and in some cases this may be desired (for example, when returning a lot of items you may want to prompt the user for a default or preferred option).

Give article feedback

Tell us how we can improve this article

Code samples are inaccurate/outdated.
I expected to find other/more information.
There are typos/broken links/broken page elements.
Content is inaccurate/outdated.
Other
By checking this box you consent to Progress contacting you by email about your response on this page.