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

Databound to value not in drop down options

3 Answers 67 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 08 Jul 2020, 03:05 PM

TLDR Version:

In situations where a databound value falls outside the options on a RadComboBox, how can I over-ride the default behavior (selecting the first option in the list) with showing the value as empty?

Example:

If I have a RadComboBox with selectable options A,B,C and D and it is bound a field with current value of G, I want the value of the RadComboBox to be empty, rather than defaulting to option A.

Business details (If interested)

We have a business object that contains an employee who is responsible for it.  This is selected and edited by a RadComboBox.  This works well in typical usage.

However, when an employee leaves the company, the business object will still list them as the person responsible for it.  The next time the item is edited, the ex-employee will no longer be in the drop-down select list.  This causes the RadComboBox to default to the first employee on the list, with no warning that the field needs to be intentionally selected before saving.

We would like to be able to control the behavior when an ex-employee is on the object, the combobox will show up as empty, and thus trigger the required field validation.  (Our rule is that the person must be updated upon the first edit after they leave.)

3 Answers, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 13 Jul 2020, 10:06 AM

Hi Greg,

From your description, I understand that the RadComboBox is located inside the Template of another control (a binding container) that allows you to bind fields to the Combo. Can you share more details on the current structure?

Depending on which control is used as a binding container, the approach to have a conditional selection is a little different. Whether the Combo and its parent control are binding on the server or on the client is also an important factor. Therefore, we need to know more about the structure you have now and we can advise you accordingly.

Kind regards,
Attila Antal
Progress Telerik

0
Greg
Top achievements
Rank 1
answered on 20 Jul 2020, 05:03 PM
Sorry for the slow reply, I was on vacation for a week.  The Rad ComboBox is hosted inside the EditItemTemplate of a FormView control which is bound to an EntityDataSource.  All binding is done on the server.
0
Eyup
Telerik team
answered on 23 Jul 2020, 09:57 AM

Hi Greg,

 

You have couple of ways to achieve this requirement:

1. EmptyMessage:
https://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/appearance-and-styling/using-the-emptymessage-property

2. DefaultItem:
https://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/radcombobox-items/default-item

3. Custom text (input enabled) - that way the combo won't select anything automatically:
https://demos.telerik.com/aspnet-ajax/combobox/examples/overview/defaultcs.aspx

I hope this will prove helpful.

 

Regards,
Eyup
Progress Telerik

Tags
ComboBox
Asked by
Greg
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Greg
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or