ASP.NET Dynamically filtering data
<p>For a project I'm working on, we're looking for a way to dynamically add filters to a page which then control the dataoutput in, for instance, a grid. We want to add the filters dynamically because we want the customer to be able to change which properties can be filtered and what filtertype (textbox, dropdown, colourpicker, etc.) should be used.</p>

<p>The filter should work as follows: 
- The customer links a filter to a certain property and specifies the filtertype (for this example: dropdown).
- A user control which contains all the filter loads all filters specified
- The filters load all values of the specified property as options. The first time the page loads; this would be the values of all items.
- Now the user selects a value from one of the filters; the page reloads
- Only items which have the specified filter value are retrieved, the user may specify one or more filters at the same time.
- Once a user drills down by filtering, only filtervalues of the retrieved items should be used in the other filters.</p>

<p>I have the following problems:
- When I create the filters runtime, events are lost because the controls get recreated each postback. 
- I could place the filters in PreInit which should solve this, but then determining which controls should be loaded becomes a problem since loading all environment vars isn't finished yet
- I don't know a good way of returning all the filter values to a central point from which I can make a good query.
- The query has to be dynamic. I'm using linq which I want to make dynamic so I don't have to select everything everytime. How to make a dynamic select query based on a string stored in the database?
- I have to select items based on the filtervalues and then adjust the rest of the filters to the already made selection. That kind of messes up the whole regular databinding sequence.</p>

<p>Any help in one of the above would be great!</p>

<p>PS: One thing I thought about was passing along filter values in the postback which would have to be recognizable. That way the server could use them for selection and then create the filters and autoselect the previously selected filtervalues. I'm not quite sure how to acheive this though...</p>
