Dropdown template

I have a dropdown to select the zipcode for an address. I am just now discovering the "template" section of the dropdown, which is amazing! My only question is this. I have a Contacts table that includes contact address...Street, City, State, Zip. My dropdown template shows City, State, Zip. Text Property is set to ZipCode in my ZipCode table and the value property is set to the same.

When you select a line in the dropdown, the template fills the text with the entire template and the then stores the ZipCode to the Contacts table. Since I don't want to have duplicate City and State, I have no Textboxes set up for them. I tried to use the Change event of the dropdown to store the City and State to Contacts as follows:

${contacts.City}=${getZipCodeResults.FirstOrDefault().ZipCityName};
${contacts.State}=${getZipCodeResults.FirstOrDefault().ZipStateName};

This loads the City and State from the first row in the ZipCode table, not the selected row. How do I get the data from the selected row?

Thanks for the help

This code always gets the first item, you should get the relevant item from the Template Context which usually is named data.

I thought that as well, but data only contains the Contact table columns and nothing from the ZipCode table. When I open the template, I have access to data.ZipCityName etc.. but I cannot access it anywhere else.

If the tables are related you will have something like:

contact.Zip.ZipCityName

Otherwise you should retrieve the relevant related record from the other table manually