Telerik blogs

Generally when you want to set a default value for a parameter, you use the Value property of the parameter (this.ReportParameters["MyParam"].Value), but what to set when you want all values to be selected by default  i.e you have a multivalue parameter?

You can do that by providing an ArrayList containing all your values to the report parameter Value property. For consistency of the Tips & Tricks series, I am going to use the project from the Using Report parameters UI to sort by column blog post. Let's make the SortByColumn parameter accept multivalues by setting the MultiValue property to True. We also see that the available values for the parameters are coming from a business object we created for this purpose.

Since we already know the values we need, we can very easily create an ArrayList with all of them like this:

ArrayList selectedValues = new ArrayList(); 
selectedValues.Add("Not Sorted"); 

Of course a better solution would be to simply loop through all the rows and collect the values we need:

foreach (DataRow filterRow in select_all.Rows) 

where select_all is an instance of the ColumnSelector class i.e.

ColumnSelector select_all = new ColumnSelector();

Then all that is left is to assign the ArrayList to the Value property of our parameter:

this.ReportParameters["SortByColumn"].Value = selectedValues;

Now on initial load of your ReportViewer, the report parameter editor would always have all values selected by default. Simple enough, eh?

However, what happens if we have a DataSet as DataSource for the multivalue parameter and we have no idea what the values are? Well the same foreach loop would do the trick, the only difference is that we can get the DataTable directly:

ArrayList selectedValues = new ArrayList(); 
DataTable Mytable = this.<your_dataset>.Tables[0]; 
foreach (DataRow filterRow in Mytable.Rows) 
this.ReportParameters["MyParam"].Value = MyArrayList; 

This wasn't that hard either now, was it?

Select All parameter

When you use a ReportViewer to show your report, there is an additional "special" UI item added: <select all> designed to help you when working with our built-in parameter UI. It can be used for quickly selecting/unselecting all values at once with a single click. You can change its text through the ReportViewer's resources, namely the ReportParameterSelectAllText property.

As usual sample project is attached. Hope this helps!


About the Author

Rossen Hristov

 is Senior Software Developer in Telerik XAML Team

Related Posts


Comments are disabled in preview mode.