Getting dropdown field values from sql query under content types

Hii,

I want to populate a dropdown field in a content type using data from a SQL query.

For example, I need to fetch data like FormName and FormDisplayName from the CMS_Form table and show it in a dropdown, filtered by the current site.

In Kentico 13, this was possible queries, but in Xperience by Kentico (XbyK), direct SQL in fields don’t seem to be supported.

What is the recommended way to achieve this in XbyK?

Should I use a custom form component, or is there any built-in approach for dynamic dropdown values?

Thanks


Environment

  • Xperience by Kentico version: [30.11.2]

  • .NET version: [8|9]

  • Execution environment: [SaaS|Private cloud (Azure/AWS/Virtual machine)]

  • Link to relevant Xperience by Kentico documentation

Tags:
Xperience Administration

Answers

I would recommend using the DropDownComponent's DataProviderType property and implement custom dropdown provider which can be used to fill the drop down options dynamically. For more details please see this guide.

Hi Tapasya,

Yes, direct SQL-driven field values from KX13 are not supported in XbyK — this is an intentional architectural change. The recommended approach is a custom form component, and it's actually cleaner and more maintainable than the old SQL query approach once set up.

How to implement it

Create a custom form component that populates a dropdown from your data source:

  1. Create a component class implementing FormComponent<TProperties, TValue> with a DropDownListComponent base or your own select rendering
  2. In the component, inject the appropriate service or use IInfoProvider<BizFormInfo> to query CMS_Form data — no raw SQL needed, use the Kentico object model
  3. Filter by current site using SiteContext.CurrentSiteName or pass the site identifier via component properties
  4. Register the component with [assembly: RegisterFormComponent] attribute

A minimal example for your use case:

[assembly: RegisterFormComponent(
    FormSelectorComponent.IDENTIFIER,
    typeof(FormSelectorComponent),
    "Form selector")]

public class FormSelectorComponent : SelectorFormComponent<FormSelectorProperties>
{
    protected override IEnumerable<HtmlOptionItem> GetHtmlOptions()
    {
        return BizFormInfo.Provider.Get()
            .WhereEquals("FormSiteID", SiteContext.CurrentSiteID)
            .Select(f => new HtmlOptionItem
            {
                Value = f.FormName,
                Text = f.FormDisplayName
            });
    }
}

If you still need raw SQL

If the data source is outside the Kentico object model (a custom table or external DB), inject IConnectionStringService and use ConnectionHelper.ExecuteQuery inside the component. This is supported but keep it to cases where no typed provider exists.

Key points to remember

  • Custom form components are reusable across all content types once registered
  • The component renders in the admin UI automatically — no additional wiring needed
  • For performance, consider caching the dropdown options if the source data changes infrequently, using IProgressiveCache


This is the fully supported path in XbyK and gives you much more control than the old SQL query approach in KX13.

Hope that helps!

@Pawan please stop giving AI answers. This one is pretty 'wrong' as JurajO points out you just need a custom DataTypeProvider for the default drop down...

Accepted answer

Tapasya,

First of all, these types of admin components don't have access to context like "current website" because within the Xperience administration UI you are not in a channel.

These types of components (like dropdowns) can be used anywhere in the Admin - Content hub, email/website/headless channel, custom admin UI pages. This means you would need to create a custom data provider or selector component for each website and specify it for each location you want to use it in.

How you specify the provider or component depends on if you want to specify the dropdown data:

  1. Through C# for a (Page or Email) Builder component or when extending the Admin UI.
  2. Through the Admin UI for something like a content type or object type field.

For option 1, use Juraj's approach with a custom data provider.

For option 2,

  1. Create a custom UI form component inheriting from Kentico.Xperience.Admin.Base.Forms.FormComponent<TProperties, TClientProperties, TValue>.
  2. Create a corresponding React component to render the data you want to expose.
  3. Register the Form Component using the Kentico.Xperience.Admin.Base.Forms.RegisterFormComponentAttribute.

You can read about this in the docs or see another example in this blog post - Embedded structured content and the power of custom data types.

To response this discussion, you have to login first.