Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Dynamic Data Add Additional Filter Criteria to Page

How should I be adding additional search/filter criteria to a Dynamic Data Web Application?

I created a Dynamic Data Web Application using the Northwind database and I am using a custom page for the Employees table (based on the ListDetails.aspx Page Template). I would like to add additional search/filter/where parameters to the Page. By default the where parameters collection is being dynamically created based on the FilterRepeater control, which is also being dynamically created based on the “foreign key” relationships the Employee Table has.

In an attempt to add additional search criteria, I have tied in to the Selecting event of the GridView's LinqDataSource and am trying to add additional items to the WhereParameters collection of the LinqDataSourceSelectEventArgs.

The problem is I can't specify what type of comparison needs to be performed. The WhereParameters collection only accepts a String and an Object, but not how to compare them. What I really would like to be able to do is add to a collection of predicate delegates...

How should I be adding additional search criteria to this page? Through attributes applied to the LINQ To SQL entity (if so, how)? What if the criteria/criterion is not based on the entity itself, how would I add to the search criteria in that case?

Aaron Hoffman

like image 385
Aaron Hoffman Avatar asked Apr 09 '09 15:04

Aaron Hoffman


2 Answers

If you want to add your own criteria to the application that isn't automatically given to you by DD, you'll have to go to DynamicDataFiltering to do that. DynamicData itself doesn't currently support custom filters and searching. It isn't difficult to implement. Josh Heyes did a great job on it.

Come back if that's not quite what you are looking for

EDIT: Also, if you are just intending on doing some further filtering of the displayed data you could write something like this maybe in the Page_Init without Josh's filtering project:

GridDataSource.WhereParameters.Add(new Parameter("it.myColumn", TypeCode.Int32, myValue));

Doing "in" or "contains" is a little more complicated than that, and would require DynamicDataFiltering.

like image 129
jlembke Avatar answered Nov 10 '22 15:11

jlembke


Here is what works in ASP.NET 4.0: http://www.olegsych.com/2010/07/understanding-aspnet-dynamic-data-filter-templates/

like image 6
Oleg Sych Avatar answered Nov 10 '22 16:11

Oleg Sych