As you probably know, Telerik Reporting comes with built-in parameters and filters. Report parameters allow users to specify or control the data used in a report. They are extremely powerful when used in expressions for filtering, sorting, grouping or even directly provide a value. When used with filters you can limit the number of records in a report based on specified filter rules. If the conditions of the rules are met, the record is included in the report. 

Let's suppose we have a string parameter that allows free user input, wired up with a filter. This way the user has the freedom to type any word and the report would be filtered based on the parameter value to show relevant information. String comparison however is case sensitive by design, so the user must be pretty precise with the provided input. The reason for the case sensitivity is that you can easily change that by applying ToLower or ToUpper on both left and right sides of the comparison, while you cannot change it the other way around (from non case sensitive to case sensitive).

So back to the free input scenario - in this case it is definitely a good idea to make the accepted input non case sensitive, to assure that there would be a proper match. We can do this using String.ToUpper method directly in the expression:

Expression                                                   Oper.   Value
=CStr(IsNull(Fields.MyField, "")).ToUpper()  =    =CStr(IsNull(Parameters.MyParam, "")).ToUpper()


Ensuring the value is not null is needed only if Allow Nulls is checked for your table column. Respectively IsNull check for the report parameter is needed if its AllowNull property (determines whether the report parameter can return Null value) is set to true.

So far so good - now we can enter a value not caring about its casing and would surely receive relevant data (if there is a match). This would work fine for a single word values, however what happens if the value consists of several words e.g. Employee Name. We would have to type down the whole name down in order to receive a record back, which is not good. In order to take care of this, we would use "LIKE" as Operator instead of "=" and a wild card in the Value expression:

          Expression                                           Oper.      Value
          =StringToUpper(Fields.MyField)          Like        ="%" + StringToUpper(Parameters.MyParam) + "%"


If we need to do some processing of the field value before using it in the filter, a possible approach would be through an user defined function, for example:

        public static string StringToUpper(object value)
            if (null == value || System.DBNull.Value == value)
                return string.Empty;
            return value.ToString().ToUpper();

Then in the filter use:

Expression                                                   Oper.   Value
=StringToUpper(Fields.MyField)                    =        =StringToUpper(Parameters.MyParam)


You can find more info on user defined functions, operators, wild chards etc. in the help topic Using Expressions.

A sample project showing the first approach is available in this code library article.



About the Author

Stefan Tsokev

Stefan’s main interests outside the .NET domain include rock music, playing the guitar and swimming.

Related Posts


Comments are disabled in preview mode.