Friday 2 January 2009

Dynamic Data Filtering – Installation

Introduction (see Dynamic Data Filtering home on codeplex)

 Josh Heyes created Dynamic Data Filtering because of missing features searches other that Equals and AND here are some of the filtering capabilities you can add by using Dynamic Data Filtering (Currently for Linq to SQL Dynamic Data Websites)

  • Searching ranges (ListPrice > 10 AND ListPrice < 500)
  • Searching in a list of possible values (Class in (‘L’, ‘M’))
  • Partial text searching (Color LIKE ‘B%’)
  • Not null or empty (DiscontinuedDate is not NULL)

Dynamic Data Filtering sample page

Figure 1 – Dynamic Data Filtering sample page

Articles in this series

  1. Installation & Adding Dynamic Data Filtering to your site
  2. Working with the DynamicFilterRepeater and the DynamicFilterForm
  3. Dynamic Data Filtering working with classic Filters and Filters  from Dynamic Data Futures project.
  4. Creating and adding custom filters
  5. Adding default values to filters
Note:  1 & 2 has been combined. 4. which is now 3. has been removed as this is as easy as having both sets of controls on the page :D

Installation of the Dynamic Data Filtering on codeplex.com (by Josh Heyes)

You will notice that there are several flavours of the install routine:

  • Dynamic Data Filtering Installer – Just what you’d expect it installs and adds the controls to the toolbox
  • Dynamic Data Filtering Assemblies Only – I think similar the above but does not add any samples etc.
  • Dynamic Data Filtering Installer w/o Toolbox Installer – This one is the same as the first but as the name suggests no toolbox entries this is specifically for users with Visual Web Developer 2008 Express which due to it’s cutdownness smile_wink for some reason does not like the toolbox installed, (Josh did explain on the Forum post where I read this but I can’t remember what it was or be bothered to do a big search on the Forum) so you will have to add the controls to the toolbox yourself if you have Visual Web Developer 2008 Express.

Steps to install and use in new website

  1. Download the Dynamic Data Filtering release from the releases page and save and run. 
    Dynamic Data Filtering installation progress 
    Figure 2 - Dynamic Data Filtering installation progress
  2. Then simple enough just follow the instructions.
  3. Now if you have Visual Web Developer 2008 Express you will need to add the controls to the toolbox manually.
     
      Create a new tab in the toolbox    
      Create NewTab Rename Tab Choose Items
      Add Tab Rename Tab Browse For Controls
           
      Click Browse Navigate to Dynamic Data Filtering folder and Click Open Check all of the Catalyst controls returned
      Click Browse Navigate to Dynamic Data Filtering folder and Click Open Check all of the Catalyst controls returned
           
      You now see the Dynamic Data Filtering controls    
      You now see the Dynamic Data Filtering controls    
      Figures 3 – 9    
           
  4. If you installed the Dynamic Data Filtering Installer then you will have an extra Data tab created, just right click on it and select rename and then name it to say DD Filtering just to keep it the same.
  5. You’re done and ready to start using Dynamic Data Filtering.

Adding Dynamic Data Filtering to your site

Setup a Dynamic Data Website (I’m going to use a file based website  because you need to do more to get it to work, and because I tend to work with file based websites), I’m going to call it DD_Filtering.

Steps to make the List page use Dynamic Data Filtering  in place of the normal filtering.

  1. Replace the LinqDataSource with  a DynamicLinqDataSource

    Just drag the replacement DynamicLinqDataSource to the page. Remember to delete the LinqDataSource first before adding the DynamicLinqDataSource and also to set the ID os the DynamicLinqDataSource to the same ID as the LinqDataSource, ID=”GridDataSource”

    Note: When you insert the first Dynamic Data Filtering control the Dynamic Data Filtering will prompt you to install the FilterTemplate folder click yes
    Install Default Filter Templates
    Figure 10 - Install Default Filter Templates

    Delete the old LinqDataSource and then click on the new data source and set the EnableDelete property to true.

  2. Replace the FilterRepeater with DynamicFilterRepeater – This is pretty much drag the new control to the page and delete the old control. Again remember to delete the FilterRepeater before adding the DynamicFilterRepeater otherwise the DynamicFilterControl’s ID will need renaming to ID="DynamicFilter" from ID="DynamicFilter0". Also you will need to set the DataSourceID to

    DataSourceID="GridDataSource".

Next we need to do some house keeping of the FilterTemplats add when we added the first Dynamic Data Filtering control, this is specifically for file based website:

 Remove the .designer.cs files from the FilterTemplates folder

Figure 11 – Remove the .designer.cs files from the FilterTemplates folder

Next you need to edit both the .ascx and .cs files to remove namespace references that are not required for a file based website and change the CodeBehind property of the control tag to CodeFile.

Here’s the quick way to do it using Visual Studio 2008 replace in files dialogue.

Cleaning up the FilterTemplates

  1. Got Edit->Find and Replace->Replace in Files (or type Ctrl+Shift+H) to get the Find and Rplace in files dialogue up.
    Find and Replace in Files dialogue
    Figure 12 – Find and Replace in Files dialogue
  2. Click the … button at the end of the Look in: textbox and set the selected folder to the DynamicData\FilterTemplates folder of your current website
    Select the Selected folder to the DynamicData\FilterTemplates folder
    Figure 13 – Select the Selected folder to the DynamicData\FilterTemplates folder
  3. Now in the Find what: textbox enter each of the find text and in the Replace with: the replace text, setting the appropriate Find options and file types in Look at these file types:
  4. Repeat step 3 for each row in the following table.
    Find what: Replace with: Find options Look at these file types:
    Inherits="$rootnamespace$. Inherits=" none *.ascx
    CodeBehind=" CodeFile=" none *.ascx
    namespace \$rootnamespace\$\n\{\n   Use: Regular expressions *.ascx.cs
    \}\n\} \} Use: Regular expressions *.ascx.cs

So if you set your Dynamic Data Website up correctly you could run it now, but you’d see NO filters!

This is because you must attribute up the the field that you want to be filtered. So you will now need to create a partials class file for the model you are using. Again I’m using the Northwind database.

So next we need some Metadata:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using Catalyst.ComponentModel.DataAnnotations;

[MetadataType(typeof(OrderMD))]
public partial class Order
{
    public class OrderMD
    {
        public object OrderID { get; set; }
        public object CustomerID { get; set; }
        public object EmployeeID { get; set; }
        [Filter(FilterMode=FilterControlMode.Range)]
        public object OrderDate { get; set; }
        public object RequiredDate { get; set; }
        public object ShippedDate { get; set; }
        public object ShipVia { get; set; }
        public object Freight { get; set; }
        public object ShipName { get; set; }
        public object ShipAddress { get; set; }
        public object ShipCity { get; set; }
        public object ShipRegion { get; set; }
        public object ShipPostalCode { get; set; }
        [Filter(FilterMode=FilterControlMode.Contains)]
        public object ShipCountry { get; set; }
        // EntitySets
        public object Order_Details { get; set; }
        // EntityRefs
        [Filter(FilterMode=FilterControlMode.Equals)]
        public object Customer { get; set; }
        [Filter(FilterMode=FilterControlMode.Equals)]
        public object Employee { get; set; }
        [Filter(FilterMode=FilterControlMode.Equals)]
        public object Shipper { get; set; }
    }
}

Listing 1 – Metadata for the Orders table

Some explanation of the filter attribute should be given here:


FilterControlMode Equivalent to:
Contains WHERE [Name] Like ‘%something%’
Equals WHERE [Name] = ‘something’
MultiSelect WHERE [Name] IN (‘one, two, three’)
Range WHERE [QTY] > 5 AND [QTY] < 15

 

I believe in the next release there will also be a named parameter of UIHint so you can specify custom FilterTemplates.

Josh Heyes had done a really great job with this.

39 comments:

Anonymous said...

Hi Steve,

I've tried Josh's dynamic data filtering 2 month ago all works except MultiSelect for some reason. Did you tried MultiSelect?

Littlered.

Unknown said...

I have try it in VB.
Metadatatype(GetType(OrderMD))_

Type 'OrderMD' is not defined

Reason ?

Anonymous said...

Thank you so much for these instructions! I was having a lot of difficulty getting the FilterTemplates to work with my existing DD website and this solved my problem!

Stephen J. Naughton said...

Moving forward I'll be concentraiting on DD v2 in .Net 4.0

Steve :D

Anonymous said...

I'm getting the folowing error on my custom 'List' page that uses Dynamic Data Filtering.

"The DynamicControl/DynamicField needs to exist inside a data control that is bound to a data source that supports Dynamic Data."

It works fine on my dev PC and has been working fine on my server until I added .Net 4.0 to the server (the app is still running 2.0). Any idea how to fix this?

Stephen J. Naughton said...

Sorry, the only thing I can suggest is that somehow you app is now running .Net 4.0, so check the Application Pool is still set to 2.0

Steve

Unknown said...

Thanks a ton Stephen...I have been looking to overcome the namespace reference error. But couldn't get over with it. Your blog just saved me. I don't know why Google search didn't display your blog link in top 3 result?? I think Google's web crawler aren't doing good job. ;) Well...but I'm glad I found your simple and well explained article and saved myself. Thank you once again!

Stephen J. Naughton said...

Well Google keeps dropping me from search results for some reason and I can't find out what the issue is, Bing.com seems fine though.

Steve :D

Asmor said...

Many thanks! I've had a hell of a time finding any documentation about getting this stuff running.

Stephen J. Naughton said...

Your welcome Asmor, Josh seems to have given up on thos project with the advances made in DD4.

Glad I could help

Steve :D

Anonymous said...

Thanks Steve, for the help you've put into this. I've just added Filtering to a Dynamic Data Web Application, with Entity Framework, but on accessing the List.aspx page, I get the error "The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'."

Any idea what I could do? Right now I'm stuck on .NET 3.5

Stephen J. Naughton said...

Hi ID, sorry Josh never updated the project to work with EF only Linq to SQL.

Steve.

Thw only option for EF is .Net 4 and DD4.

Anonymous said...

hi,
When I am trying to install "Dynamic Data Filtering Installer" I get the error :
"Toolbox control installer must be installed before running this installer"

where I find this toolbox control installer?

Stephen J. Naughton said...

I've had that error, have a look there were two downloads one worked for me and one didn't.

Steve :D

Anonymous said...

Very Helpful! Very Helpful indeed!
I am praying for .NET4 tho.
Thank you very much!

Stephen J. Naughton said...

Yes this sort of think is all build in in .Net 4 and lots more to.

Steve

Anonymous said...

In figure 10 you indicate that the filter templates automatically install when you add the first control. I am not getting that. I am not sure what I am missing. Thanks in advance!

Stephen J. Naughton said...

Hi not sure what is going on this was just my experience, and Josh does not seem to be doing any more with it.

The good news is .Net 4 & DD4 has this with bells on.

Steve

Anonymous said...

Hi Steve,

Thanks for detailed steps. Can this be used with DomainDataSource. I want to save the filter state in the URL's query string so that the users can bookmark the link and revisit the search results at will. Is it possible or can you point me in the right direction?

Stephen J. Naughton said...

No it only works with DD and .Net 3.5 SP1 but the good news is DD and .Net 4 has this with bells on.

Steve

Anonymous said...

Thanks a lot your article
May you see a thing:
Export excel from List. All of object result from filter search is exported.
I have done exporting excel by make Ado.net datatable from Linq. But I only print all of object (can not print result of filtering)

Stephen J. Naughton said...

Have a look at Matt Berseth's Export GridView to Excel as long as the button is outside theupdate pannel it works fine, with the filtered data. Have fun.

Steve

Anonymous said...

Hi!
unfortunately, I clicked NO on Create Templates? Form show up. I feel regret now for that moment. How can I get Filter Templates Folder again?
Thanks in advance

Stephen J. Naughton said...

The easyest way would be to create an empty project with same name etc. in a new folder somewhere and then add Filtering again say yes this time and then copy the bits to your current project.

Steve

Anonymous said...

Thank you so much!
I've done what you said but it didn't work for me.
Although I tried to install Dynamic Data Filtering on another computer but there isn't any message box show up. Would if bother you if you send the files to my mail box?
ideas1020@yahoo.com
Thank you!

Stephen J. Naughton said...

Sorry about that, Josh Heyes does not seem to be around anymore so I can't help any more than that. Do you have the option to use VS2010 and .Net 4? if so a much more flexible filtering solution.

Steve

Bob said...

I've followed the tutorial but as soon as a view a list page I get

'Object reference not set to an instance of an object'

'[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.UI.WebControls.LinqDataSourceView.GetTableMetaDataMembers(ITable table, Type dataObjectType) +10
System.Web.UI.WebControls.LinqDataSourceView.StoreOriginalValues(IList results) +61
System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +343
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74'

Any ideas?
James

Stephen J. Naughton said...

Hi Bob, first of all this will only work with Dynamic Data and .Net 3.5 and will not work with DD and .Net 4. However in .Net 4 there is a much more powerfull filtering system.

Steve

Bob said...

I have installed from Nuget your custom filters. What I'm getting though is

The type or namespace name 'QueryableFilterUserControl' does not exist in the namespace 'System.Web.DynamicData' (are you missing an assembly reference?)

Any ideas?

Stephen J. Naughton said...

Hi Bob, are you running a Filebased website or a WAP Web Application Project?

ALL My NuGet samples are for WAP.

Steve

Bob said...

Ahh, a filebased website.

Stephen J. Naughton said...

Hi Bob, that's not an issue you will need to convert the filters to file based website CodeBehind to CodeFile etc. but the main issue I think is that the initial version of my filters is that they use a local class LinqExpressionHelper.cs in the Classes folder you will need to move these to App_Code folder and remove the namespace.

I plan to add a PowerShell script later to do this for you :)

P.S. new version of thew filters will use a set of shared class libraries.

Steve

Bob said...

Thanks

I tried doing it manually but ended up with lots of errors.

Stephen J. Naughton said...

Hi Bob, feel free to mail me direct, my e-mail is in the top right of this site :)

Steve

Lee Mandeville said...

Hi,

was a solution found to the Object reference not set to an instance of an object. error on the list page?

Thanks

Stephen J. Naughton said...

Hi Lee, I don't know I was never a part of this project and I think the author became disillusioned with MS sadly.

It's worth noting that this is not compatible with > .Net 3.51 and a better solution was introduced with DD for .Net 4 and greater.

Steve

Andrew said...

It is not too difficult to port a .NET 3.5 site running this code to .NET4+. Just remove the filter bits and replace with filter bits from an up to date tutorial. This worked for me.

Unknown said...

I can't find the LinqDataSource, is it the same as the EntitiesDataSource? as well as the FilterRepeater, what i have is a QueryableFilterRepeater, are they the same?

Stephen J. Naughton said...

hi there, in 2009 there was only the LinqDataSource EF had not gone live then, and today in VS2013/2015 the LinqToSql project type has gone away. This area has all changed as it from what they were trying to do. The ended up adding a much better system that is now built in so you don't need this unless you are still using Vs2008 SP2.

Steve