问题
I have an ASP.NET Dynamic Data application that includes two tables, Departments and KPI's. When I capture KPI's, on the 'List' view, I set the Department field of the dynamic filter to e.g. 'Plant 1', but when I add a new KPI, I still have to select 'Plant 1' in a dropdown.
Is there any way I can cause the dropdown in the 'Insert' view to correspond to the dropdown in the dynamic filter? I can just see users filtering on 'Plant 1', and assuming any KPI's they add will fall under 'Plant 1'.
回答1:
I think what you want is to "Capture current filter criteria from List view when Insert link is clicked and use that filter criteria as the default values on Insert Page (ex: for foreign key relationships, DropDown Lists)"
The Dynamic Data Futures project does something like this. Check out: http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=14475 for the code. Run the "DynamicDataFuturesSample" web project and look at the section "Populate Insert templates with values from filters"
FROM DynamicDataFutres:
Populate Insert templates with values from filters
By default, Dynamic Data does not prepopulate relationship (foreign key) fields in an Insert view with default values. The DefaultValueHelper class contains helper methods that set up the Dynamic Data templates in such a way that the relationship fields are populated using values from the URL...
Also, Stephen Naughton has a blog post that solves the same problem (grabs filter criteria from query string)
http://csharpbits.notaclue.net/2009/01/getting-default-values-from-list-page.html
来源:https://stackoverflow.com/questions/1795249/dynamically-set-defaults-for-scaffolded-tables-according-to-dynamic-filters