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")+"'>" #%}
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>"; } %}
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!
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>") %}
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 %}
Unfortunately '{% City %}' doesnt work. The "{% %}" breaks since it is inside another "{% %}"
Please, sign in to be able to submit a new answer.