Databound to value not in drop down options

4 posts, 0 answers
  1. Greg
    Greg avatar
    4 posts
    Member since:
    Feb 2015

    Posted 08 Jul Link to this post

    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.)

  2. Attila Antal
    Admin
    Attila Antal avatar
    571 posts

    Posted 13 Jul Link to this post

    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

  3. Greg
    Greg avatar
    4 posts
    Member since:
    Feb 2015

    Posted 20 Jul in reply to Attila Antal Link to this post

    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.
  4. Eyup
    Admin
    Eyup avatar
    4027 posts

    Posted 23 Jul Link to this post

    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

Back to Top