I’ve reached the time for a design decision on how to indicate ‘none selected’ in a data bound ComboBox. I wish to apply this to all future occurrences where a ComboBox needs this. One cannot set SelectedIndex to -1 on data bound combos, nor can one set SelectedValue to null.
Commonly suggested solutions are to add a dummy row to the combo, but without knowledge of the objects bound to rows, a combo cannot reliably create a dummy object in such a way as to display the ‘none selected’ message. I don’t want to add another item on the data source, as this will compromise the list for other clients that don’t use a dummy object.
What other options are there? BTW, I’m using a Telerik RadComboBox, but this scenario is not specific to the Telerik control.
You can define the ’empty item’ in the markup, and append any data-bound items:
The key is to specify AppendDataBoundItems=’true’ to append the data-bound items to any items that were specified directly in the markup.
This works for the standard ASP.NET DropDownList but also for the Telerik RadComboBox.