This is a migrated thread and some comments may be shown as answers.

Silverlight Report Parameters?

2 Answers 212 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 2
Ryan asked on 09 Nov 2010, 05:00 PM
I need an example of how to allow users to view a report with a default date range and allow them to change the start and end dates outside the ReportViewer with SilverLight 4/ Reporting 2010 Q2 SP1/ RIA Domain Data Sources. 
Right now I just need this to work , but project team that I'm on uses MVVM but from what I understand from other posts binding is not posible (please correct me if this is wrong). 

2 Answers, 1 is accepted

Sort by
0
Ryan
Top achievements
Rank 2
answered on 09 Nov 2010, 08:18 PM
public MainPage()
{
InitializeComponent();
this.ReportViewer1.RenderBegin += new RenderBeginEventHandler(ReportViewer1_RenderBegin);
}
void ReportViewer1_RenderBegin(object sender, RenderBeginEventArgs args)
{
//single value parameter
args.ParameterValues["ProductCategory"] = "Components";
//multi value parameter
args.ParameterValues["ProductSubcategory"] = new object[] { "Brakes", "Chains" };
}

Found the solution using Google instead of the Forum search. 
http://www.telerik.com/support/kb/reporting/report-viewers/programmatic-initialization-of-report-parameter-values-in-telerik-reporting-silverlight-viewer.aspx

0
Alexander
Top achievements
Rank 1
answered on 21 Sep 2011, 11:03 AM
Hi!

I use the same approach in an bahavior - so i can bind my parameter values to my viewmodel.

with my beahvior, my XAML looks like that:
<Silverlight:ReportViewer x:Name="ReportViewer1" ReportServiceUri="myServiceAddress" Report="myReportClass, myReportAssembly">
                                    <i:Interaction.Behaviors>
                                        <coreBehavior:BindReportParametersBehavior>
                                            <coreBehavior:BindReportParametersBehavior.ReportParameterBindingCollection>
                                                <coreBehavior:ReportParameterBinding Parametername="parameter1" Value="{Binding myViewModel.Value4Parameter1}"/>
                                                <coreBehavior:ReportParameterBinding Parametername="parameter2" Value="{Binding myViewModel.Value4Parameter2"/>
                                            </coreBehavior:BindReportParametersBehavior.ReportParameterBindingCollection>
                                        </coreBehavior:BindReportParametersBehavior>
                                    </i:Interaction.Behaviors>
                                </Silverlight:ReportViewer>

this is my behavior:
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Interactivity;
using Telerik.ReportViewer.Silverlight;
 
namespace rsorb.client.core.Behavior
{
    /// <summary>
    /// Behavior to Bind the Values TelerikReportParameters to the ViewModel
    /// </summary>
    public class BindReportParametersBehavior : Behavior<ReportViewer>
    {
        #region Dependency Properties
         
        /// <summary>
        /// Collection for the Bindings
        /// </summary>
        public ReportParameterBindingCollection ReportParameterBindingCollection
        {
            get { return (ReportParameterBindingCollection)GetValue(ReportParameterBindingCollectionProperty); }
            set { SetValue(ReportParameterBindingCollectionProperty, value); }
        }
 
        // Using a DependencyProperty as the backing store for ReportParameterBindingCollection.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ReportParameterBindingCollectionProperty =
            DependencyProperty.Register("ReportParameterBindingCollection", typeof(ReportParameterBindingCollection), typeof(BindReportParametersBehavior), new PropertyMetadata(new ReportParameterBindingCollection()));
 
        #endregion
 
 
        #region Attached/Detached
        /// <summary>
        /// Attach
        /// </summary>
        protected override void OnAttached()
        {
            base.OnAttached();
            this.AssociatedObject.RenderBegin += new RenderBeginEventHandler(AssociatedObject_RenderBegin);
        }
        /// <summary>
        /// Detach
        /// </summary>
        protected override void OnDetaching()
        {
            this.AssociatedObject.RenderBegin -= AssociatedObject_RenderBegin;
            base.OnDetaching();
        }
        #endregion
 
 
        #region Private Methods
        /// <summary>
        /// Assign the parametervalues
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void AssociatedObject_RenderBegin(object sender, RenderBeginEventArgs args)
        {
            foreach (var reportParameterBinding in ReportParameterBindingCollection)
            {
                // Set the DataContext of the ListItem (this makes the bindings work)
                if (reportParameterBinding.DataContext == null)
                    reportParameterBinding.DataContext = this.AssociatedObject.DataContext;
                args.ParameterValues[reportParameterBinding.Parametername] = reportParameterBinding.Value;
            }
        }
        #endregion
    }
 
    /// <summary>
    /// Collectionclass for the bindings
    /// </summary>
    public class ReportParameterBindingCollection : ObservableCollection<ReportParameterBinding>
    {
         
    }
 
 
    /// <summary>
    /// Represents an item for the Binding-Collection
    /// </summary>
    public class ReportParameterBinding : FrameworkElement
    {
        /// <summary>
        /// Name of the reportparameter
        /// </summary>
        public string Parametername
        {
            get { return (string)GetValue(ParameternameProperty); }
            set { SetValue(ParameternameProperty, value); }
        }
        public static readonly DependencyProperty ParameternameProperty =
            DependencyProperty.Register("Parametername", typeof(string), typeof(ReportParameterBinding), new PropertyMetadata(string.Empty));
 
 
 
        /// <summary>
        /// Value of the reportparameter
        /// </summary>
        public object Value
        {
            get { return (object)GetValue(ValueProperty); }
            set { SetValue(ValueProperty, value); }
        }
 
        // Using a DependencyProperty as the backing store for Value.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ValueProperty =
            DependencyProperty.Register("Value", typeof(object), typeof(ReportParameterBinding), new PropertyMetadata(string.Empty));
    }
}

Tags
General Discussions
Asked by
Ryan
Top achievements
Rank 2
Answers by
Ryan
Top achievements
Rank 2
Alexander
Top achievements
Rank 1
Share this question
or