Skip to main content

Filtering in SPGridView with properties from the Child-table

·221 words·2 mins

I can get the value from the child-record to show by using the selecting-event of the LinqDataSource and using, for example:

e.Result = var record from Parent
             select new {
             ParentID = record.ParentID,
             Name = Parent.Name,
             ChildProperty = Child.Property,
             ...
             }

Somehow, however, this screws up the filtering-part. Even when I disallow filtering on the columns from the child-record, the SPGridView only gives me “Loading…” in the WebPart for the filter. Reason for this seems to be that I had a “this.Page.Response.Write” in my page. Removing that fixed the initial problem of having no list to select the filter from.

At the moment, I’ve also added a property in my DataContext-code which returns the child-property (effectively: public string ChildProperty() { get {return this.Child.Property; } }). This replaces the Selecting-eventhandler.

When I want to apply the filter, I now get a new error: The member ‘Child.Property’ has no supported translation to SQL. I get the same error with the added ‘property’ in the DataContext-code as with the Selecting-eventhandler.

So, anyone with a solution for this problem? I can get it to work if I set the ID I base the actual value on as filter-value, but then, when I show the list of possible values to filter on, I get the values instead of the names… Which is not the desired effect…