M# Tutorials

Learn to build .NET applications with M#. Our step-by-step tutorials will get you up-to-speed rapidly.
If you already know ASP.NET and C#, you can master M# in a week or two.

Filter triggers

You may have to filter some lists in your form depending on the value of another list, for example when you select a country you want to filter the list of cities and only show cities associated to the selected country. In this lesson we will learn how to perform such operations with M#.

Requirements

We have to store the city of the employee and create a form with dropdowns on many levels.
For doing this, we won't display a list of all cities in the world, we have to optimize this and filter results for the end user.
We will create 3 new entities: Country, Region and City.

Now let's associate the city with the employee and create a form on employee.

If you open your form the lists are all displaying all the data, but we need to filter this.
Let's see how M# allows us to perform such operations with ease.

Trigger

In your M# module, go to the bottom of the page and open the "Filter Triggers" area. Click on the line for adding a new element and look at the list.

This list displays all drop-downs in your form, for the Country/Region filter we need to select "Country --> Region".
If you display the form the list of regions will be empty and if you change the country nothing change.

Filter

We have to give the filter criteria to our new filter.

If you display the form once again nothing change again when we change the country, that's because the country drop-down doesn't use postback, let's change this.

Now if you change the country the list of regions will be filtered. Do the same for the City drop-down list, we now have the following module.

Alternative

As you saw in this tutorial it is very easy to filter related dropdowns in M#.
You can find other alternatives to this if you need more, for example you may want to hide the Region drop-down list if no country is selected. To do this you will have to use the GetActiveValue() method, this method will return the selected in the form. The following illustration shows you how to hide the region drop-down list if no country is selected.