I have a GridView, bound to a SqlDataSource. The SqlDataSource points to a table with seveeral fields, including an Activity Date field and a Name field.
By default I want it to display every entry in the table, but I want to be able to dynamically filter it with three possible variables: A Before date, an After date, and a Name, all of which are selected from separate DropDown lists. For example, if a user picks a Before Date, I want to filter out all entries with dates prior to the Before Date. If the user selects an After date, I want to filter out all entries with dates later than the After date. If both are selected, then both. And at any time, I want to limit all entries to those with the specified Name.
I have written the following Filter Expression:
[Name] = '(0}' AND [Activity Date] > '{1}' AND [Activity Date] < '{2}'
'(0)' = A Name selected value of a DropDownList.
'{1}' = Date,, which is selected on a Calendar and written to a Field.
'{2}' = Date, which is selected on a Calendar and written to a Field.
The problem is this: Dates are only applied to the Filter if a Name has already been selected. Ex. If I pick Before and After dates, nothing happens, but if I then pick a Name, then all three are applied. If I pick a Name first, it is applied. Any Dates I select after that are also applied.
Why would it be working this way, and is there a better method than that which I am using?