Set Initial Value to a Drop Down List

lasa jay asked on January 18, 2017 07:06

Hi Kentico,

I would like to set a initial value to a drop down field within a Kentico form. The standard required field validation must fail if the user does not select any other options.

Basically, I am trying to imitate the initial value functionality provided by the RequiredFieldValidator in ASP .NET, please let me know if this is possible within Kentico forms.

Thanks in Advance!

Cheers, Lasa

Correct Answer

Jan Hermann answered on January 18, 2017 07:25

Set your field as Required and first row in your dropdown as:

;(Select)

3 votesVote for this answer Unmark Correct answer

Recent Answers


Ilesh Mistry answered on January 18, 2017 10:15 (last edited on December 10, 2019 02:30)

Exactly as Jan has said make sure the field is mandantory and have the first option as empty.

Better to create a query and then call this. This is so that, should you ever need to use that option again to feed another drop down, then something like the below could also help...

SELECT t.* FROM (SELECT '' as ItemId, '-- select --' as ItemDesc UNION
SELECT something as ItemId, something as ItemDesc FROM youTable) as t ORDER BY ItemId

Then within the drop down within the SQL Query option (data source) add a macro in to call that query (custom table for this example) e.g. {% GetCustomTableQueryText("Namespace.CustomTableName.QueryName")|(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Matthijs Wensveen answered on March 2, 2018 12:31 (last edited on March 2, 2018 12:46)

Thanks, Ilesh. Is there any way to do the same (or similar) with a macro expression? I have

Documents["/Products"].Children.DisplayName#

as a macro expression, but I would like to include an initial empty item.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.