Please help me to solve the (simplified sample) scenario below .
we have 2 dropdowns (inputs with datalists). First is Countries Second is States when the first is selected the second is prepared by filtering for country.
My approach is below but dont know how to do it or not sure it is the best.
1- At page load download countries (using entity framework model) and make them datalist of countries input
2- At page load download states and append them in a kind of data list (json or something like that or as a model)
3- When the user keyup in the states input, I want to filter states with "Startwith" and "Selected Country"
and so on.
How can I do this or should I do this?
(I didn't want to solve this with entity framework to not overload the server in every key up event and wanted to solve it client side)
Your approach need to retire all the countries and states to client side , recreate the dropdownlist in javascript each time after section changed of countries . IMO that is big risk in performance and should avoid that . I would suggest dynamically load
the states dropdownlist based on the section of country :
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
This is the concept of Cascading drop down controls. In your states dropdown change event you call jQuery that will fill the city dropdown based on the selected states in the states dropdown.
If you want to filter out all the cities based on states ddl selected value, then you have to keep all the cities with there states in json format in some hidden text box. Then you filter the cities values from the json and bind the city ddl with it.
Helping you always. Don't forget to click "Mark as Answer" on the post that helped you.
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠
Member
90 Points
520 Posts
Right approach to Create Dynamic Dropdown lists
Jan 19, 2019 06:39 AM|fatihbarut|LINK
Hi all,
Please help me to solve the (simplified sample) scenario below .
we have 2 dropdowns (inputs with datalists). First is Countries Second is States when the first is selected the second is prepared by filtering for country.
My approach is below but dont know how to do it or not sure it is the best.
1- At page load download countries (using entity framework model) and make them datalist of countries input
2- At page load download states and append them in a kind of data list (json or something like that or as a model)
3- When the user keyup in the states input, I want to filter states with "Startwith" and "Selected Country"
and so on.
How can I do this or should I do this?
(I didn't want to solve this with entity framework to not overload the server in every key up event and wanted to solve it client side)
thanks.
All-Star
18785 Points
3830 Posts
Microsoft
Re: Right approach to Create Dynamic Dropdown lists
Jan 21, 2019 06:35 AM|Nan Yu|LINK
Hi fathbarut ,
Your approach need to retire all the countries and states to client side , recreate the dropdownlist in javascript each time after section changed of countries . IMO that is big risk in performance and should avoid that . I would suggest dynamically load the states dropdownlist based on the section of country :
https://www.c-sharpcorner.com/article/dynamically-bind-the-dropdownlist-on-change-event-in-asp-net-mvc-5/
Best Regards,
Nan Yu
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Participant
1060 Points
732 Posts
Re: Right approach to Create Dynamic Dropdown lists
Jan 21, 2019 12:55 PM|yogyogi|LINK
This is the concept of Cascading drop down controls. In your states dropdown change event you call jQuery that will fill the city dropdown based on the selected states in the states dropdown.
Kindly check this reference tutorial - How to Populate Cascading Dropdownlist with AJAX in ASP.NET
If you want to filter out all the cities based on states ddl selected value, then you have to keep all the cities with there states in json format in some hidden text box. Then you filter the cities values from the json and bind the city ddl with it.
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠