Last post Sep 10, 2015 08:51 AM by sjnaughton
Sep 09, 2015 08:56 AM|adriang133|LINK
I have created a custom filter on my dynamic data website which uses a custom expression in my QueryExtender to catch the IQueryable with the data and then filter it. This works fine but when I select a value in my custom filter it's not added to the routeValueDictionary
that's used to build the Insert Action path.
protected override void OnPreRenderComplete(EventArgs e)
RouteValueDictionary routeValues = new RouteValueDictionary(GridView1.GetDefaultValues());
InsertHyperLink.NavigateUrl = table.GetActionPath(PageAction.Insert, routeValues);
If I change one of the automatically added DynamicFilters in the QueryableFilterRepeater then it does get added in the route values and it sends me to the filtered insert page. How can I add my custom filter values to the route values ? I can do a caveman
workaround by just manually adding the filter values after the call to GetDefaultValues() but I think there should be a better way.
Sep 09, 2015 11:05 PM|Zhi Lv - MSFT|LINK
The RouteValueDictionary represents a case-insensitive collection of key/value pairs. And the RouteValueDictionary Constructor (Object) initializes a new instance of the
RouteValueDictionary class and adds values that are based on properties from the specified object. So, please check the filter values.
You could use the following code to add value into RouteValueDictionary.
var routeValues = new RouteValueDictionary();
Here are some relevant articles, please refer to them:
Sep 10, 2015 02:56 AM|adriang133|LINK
I know I can add the values like that but it's a kind of ugly workaround. The values for the dictionary are retrieved by calling
so Instead of me adding my filter values after that call I'd like it to happen before that call, so they're retrieved by calling that function and I don't have to change the code in all of my List.aspx pages. This would be a better and more elegant solution
than simply adding them after the GetDefaultValues() because I have more List.aspx pages and I don't want to have to change my code in all of them. I hope you understand where I'm getting at.
Sep 10, 2015 08:04 AM|sjnaughton|LINK
adriang133, the bottom line is if the filter you are adding is not an actual filter then the system has no way of finding out what you have filtered by. this is because when a filter is applied that is when it is added, so you could add a custom filter
control and make it hide it's self and let it do the filtering, or you can modify the "OnPreRenderComplete" method and add it there :(
Sep 10, 2015 08:37 AM|adriang133|LINK
Thanks Steven! It turns out what I was trying to do (a filter whose value persists through pages that have foreign key filters referencing the same entity) can be achieved a lot easier and cleaner by just creating a custom filter control and a custom FilterFactory.
I have now implemented it that way and everything works fine.
Sep 10, 2015 08:51 AM|sjnaughton|LINK
that is great news, I would have gotten to that eventually :D