FAQ/Questions/How-To-Preset-Values-In-Filter.md
... ...
@@ -13,7 +13,7 @@ You can use hidden filter to make reports pre-filtered whenever they are opened
13 13
14 14
###Example: Presetting a time period (From a year ago to Today)
15 15
16
-##Global.asax (C♯)
16
+###Global.asax (C♯)
17 17
```csharp
18 18
public override void PreExecuteReportSet(ReportSet reportSet)
19 19
{
... ...
@@ -45,7 +45,7 @@ You can use hidden filter to make reports pre-filtered whenever they are opened
45 45
```
46 46
47 47
48
-##Global.asax (VB.Net)
48
+###Global.asax (VB.Net)
49 49
```visualbasic
50 50
Public Overrides Sub PreExecuteReportSet(reportSet As ReportSet)
51 51
MyBase.PreExecuteReportSet(reportSet)
... ...
@@ -74,7 +74,49 @@ Public Overrides Sub PreExecuteReportSet(reportSet As ReportSet)
74 74
End Sub
75 75
76 76
```
77
-##Screenshots
77
+###Screenshots
78 78
79 79
![](http://wiki.izenda.us//FAQ/Questions/How-To-Preset-Values-In-Filter/Time_Period.png)
80 80
81
+##Example: Allowing the user to modify the filter value
82
+
83
+The above example does not allow the user to change the filter value as the filter is hidden. In order to allow a preset value that responds to user input, a different approach is required. First, we have to know when the report is first being accessed by a user. This can be tricky since Izenda does not track when a report is first being accessed versus subsequent requests to render the report with different filter values. Since the CustomAdHocConfig usually exists in the global.asax, checking if the request is a postback is not possible, so we have to use some other method. For the following example, imagine we have a report with the following:
84
+
85
+* A filter on OrderDate with a "Between (Calendar)" operator
86
+
87
+We are going to leave the filter values blank in the report definition so that we are able to have a baseline from which to determine if we need to set the filter values to their default or not.
88
+
89
+###Global.asax (C♯)
90
+```csharp
91
+public override void PreExecuteReportSet(ReportSet reportSet)
92
+{
93
+ base.PreExecuteReportSet(reportSet);
94
+
95
+ // if (reportSet.ReportName != "MyReport" || reportSet.ReportName != "MyReport2") // You can choose to which report this overriding to be applied
96
+ // return;
97
+
98
+ foreach (Izenda.AdHoc.Filter filter in reportSet.Filters)
99
+ {
100
+
101
+ if (filter.Operator == OperatorTypes.BetweenTwoDates)
102
+ { // can choose filter as well based on its operator
103
+
104
+ if (filter.dbColumn.Name.Equals("OrderDate"))
105
+ { // To be applied to "OrderDate" filter
106
+
107
+ if (filter.Values.GetValue(0).ToString().Equals("") && filter.Values.GetValue(1).ToString().Equals("")) //check whether the filter values are the default
108
+ {
109
+ DateTime baseDate = DateTime.Today;
110
+
111
+ filter.Values.SetValue(baseDate.AddYears(-1), 0); //the'Between' operator takes two parameters. the first one's indexed as 0. '-1' for a year ago
112
+
113
+ filter.Values.SetValue(DateTime.Today, 1);
114
+
115
+ // reportSet.Filters[count].Values.SetValue("01/01/2010", 1);
116
+ // reportSet.Filters[count].Values.SetValue("01/01/2016", 1); // the date value could be a specific date
117
+ }
118
+ }
119
+ }
120
+ }
121
+}
122
+```