Kentico 11 Drop-Down 2 dependant on Drop-Down 1 selection

Roberto Gonzalez Jr asked on January 9, 2021 05:20

I am looking to have 2 drop-downs with multiple options populated from a custom table.

My first drop down is populated by an SQL selection of a column in a custom_table.

My second drop-down or just a text field displaying an integer that corresponds to the selected option that needs to be dependent on the first drop-down selection.

How would I create an SQL query to take another fields value and compare it in the table to display the corresponding integer?

My table has an ItemID, DateTime, Spaces

The first drop down displays all dates available and depending on the date selected I would like to show how many space in the second drop-down.

SQL Example

Field Name: Date Drop-down 1 SELECT ItemID,DateTime FROM custom_table

Field Name: Spaces Drop-down 2 SELECT ItemID,Spaces FROM custom_table

How can I add a condition to the SQL so that it is inter-dependent. Is there any example someone can provide?

Thanks

Recent Answers


Brenden Kehren answered on January 9, 2021 06:25

0 votesVote for this answer Mark as a Correct answer

Roberto Gonzalez Jr answered on January 9, 2021 13:42

Yes Brenden, I have seen the article several times and it describes condition based on true or false.

An example I saw was the following.

form tablequeryquery data sourcecustom tabledrop down list Correct Answer Dmitry Bastron answered on May 29, 2020 23:27 Tom, this can be done like this:

First form field, let's call it Frequency, is configured as:

Data type: Text Form control: Drop-down list Data source: list of options 50Hz 60Hz Has depending fields: true Second form field, GeneratorModel is configured as:

Data type: Text Form control: Drop-down list Data source: SQL Query (will be below) Depends on another field: true Query:

select GeneratorCode, --this is drop-down item value GeneratorName --this is drop-down item display name from customtable_Generators where GeneratorFrequency = '{% Fields["Frequency"].Value #%}'

My SQL query is similar but I am getting and error

Select ItemID,Spaces from custom_table where DateTimeSpaces='{% Fields["DateTime"].Value #%}'

I get an error Where DateTimeSpaces="1" Caused exception:Conversion failed when converting date and/or time from character string.

So I am trying to display the number of spaces that belong to the corresponding DateTime field on my form which is has a date time format.

How would I correct this error or the SQL?

0 votesVote for this answer Mark as a Correct answer

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