Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Data: how to filter dropdown for foreign key on edit page

Using Linq-to-SQL and Dynamic Data.

On a Dynamic Data edit screen, a dropdown lists the possible values for a foreign key.

I need to filter the values listed in this dropdown, preferably by adding a where clause on the linq-to-sql query.

Any ideas?

like image 668
Leon van der Walt Avatar asked Jan 22 '23 11:01

Leon van der Walt


1 Answers

Well, I found a place to customize this, although I still have not found a way to override or extend the linq query for loading the data:

In the file \DynamicData\FieldTemplates\ForeignKey_Edit.ascx.cs (as per default location), in the Page_Load method the following call is made:

PopulateListControl(DropDownList1);

This can be replaced entirely with your own code. In my case, I first checked if the current table implements a custom interface I defined. If it does, use that to get the data to bind the dropdown, else pass control on to PopulateListControl.

Using Reflector, it seems that PopulateListControl ultimately uses MetaTable.GetQuery() to get a default list query for a table. Would have been nice to extent that instead.. but moving on to other things now!

like image 82
Leon van der Walt Avatar answered May 13 '23 13:05

Leon van der Walt