binding datalist with all the records in the custom table .

Ashton Khizr asked on September 13, 2017 16:26

How I can fetch all the distinct records from 2 columns of the custom table and bind them with datalist in Kentico?

<datalist id="suggestions"  >
 <option value="Albama">

 {% "<option value='"+GlobalObjects.CustomTables["customtable.Location"].Items[0].GetValue("StateShortName")+"'>" #%}

Correct Answer

Trevor Fayas answered on September 13, 2017 23:02

Works in debug, but may not in your context. okay, try this:

{% foreach(x in GlobalObjects.CustomTables["customtable.LocationData"].Items.Columns("Distinct StateLongName, City")) { "<option value=\""+x["City"]+"\"></option>"; } |(identity)GlobalAdministrator%}

0 votesVote for this answer Unmark Correct answer

Recent Answers


Trevor Fayas answered on September 13, 2017 17:05

GlobalObjects.CustomTables["customtable.Location"].Items.OrderBy("StateShortName, StateDisplayName").Columns("Distinct StateShortName, StateDisplayName").ApplyTransformation("<option value=\"{% StateShortName %}\">{% StateDisplayName %}</option>")

This is assuming the other column is "StateDisplayName" just adjust as you need!

0 votesVote for this answer Mark as a Correct answer

Ashton Khizr answered on September 13, 2017 20:42 (last edited on December 10, 2019 02:31)

Thanks Trevor for the response I tried that and following was my code. it doesnt add "city" as the value instead it is blank. What did I do that is wrong?

{% GlobalObjects.CustomTables["customtable.LocationData"].Items.Columns("Distinct StateLongName, City").ApplyTransformation("<option value='"+City+"'></option>") |(identity)GlobalAdministrator%}
0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on September 13, 2017 20:44 (last edited on December 10, 2019 02:31)

The apply transformation renders as it's own macro expression, so you need to use:

{% GlobalObjects.CustomTables["customtable.LocationData"].Items.Columns("Distinct StateLongName, City").ApplyTransformation("<option value='{% City |(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Ashton Khizr answered on September 13, 2017 22:52 (last edited on March 24, 2018 12:15)

Unfortunately '{% City %}' doesnt work. The "{% %}" breaks since it is inside another "{% %}"

0 votesVote for this answer Mark as a Correct answer

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