Edit this page

Sorting

As of Q2 2008, RadComboBox introduces a new feature - sorting. The sorting is performed against items' Text, but you can implement your own custom sorting as well.

Enable items sorting

To enable sorting you need to:

  • Set the Sort property. Its value can be either Ascending, Descending or None (default).

    • In code-behind:

RadComboBox1.Sort = RadComboBoxSort.Descending;


RadComboBox1.Sort = RadComboBoxSort.Descending

* Inline:
<telerik:radcombobox id="RadComboBox1" runat="server" skin="Sunset" sort="Ascending"></telerik:radcombobox>
  • Call the SortItems() method of the combobox or Items.Sort() method of the items collection. These approaches are equal:

    • RadComboBox1.SortItems()

    • RadComboBox1.Items.Sort()

note

SortItems and Items.Sort methods have overload methods that accept one parameter of type IComparer . These overload methods are used if you want to implement your custom sorting.

Case sensitive sorting

Sorting is case sensitive by default. This means that the item "telerik" will be in front of item "Teleriik" if the sort type is Ascending.

To enable / disable the case sensitive sorting set the SortCaseSensitive property of the combobox to either True or False.

Sorting of data-bound items

If you want to sort the items of a combobox bound to a declarative datasource, you need to call the SortItems (Items.Sort) method in the DataBound event handler of the combobox:


protected void RadComboBox1_DataBound(object sender, EventArgs e)
{            
    RadComboBox1.Items.Sort();
}


Protected Sub RadComboBox1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadComboBox1.DataBound

    RadComboBox1.Items.Sort()

End Sub

caution

Note that DataBound event occurs after the server control binds to a data source and is different from ItemDataBound event.

See Also