Search code examples
telerik-reportingmultivaluereportparameter

Telerik Reporting How to force the 'Contract' selection whether user selects it or not


I want to force the parameter "Contract" to be returned whether the user selects it from the drop-down list or not.

enter image description here


Solution

  • You should be able to use the NeedDataSource event for that. Take a look at the documentation for it here: https://docs.telerik.com/reporting/designing-reports-parameters-programmatic-control

    Specifically pay attention to this code sample:

    private void Report1_NeedDataSource(object sender, System.EventArgs e)
    {
        //Take the Telerik.Reporting.Processing.Report instance
        Telerik.Reporting.Processing.Report report = (Telerik.Reporting.Processing.Report)sender;
    
        // Transfer the value of the processing instance of ReportParameter
        // to the parameter value of the sqlDataSource component
        // THIS IS WHERE YOU CAN FIND YOUR PARAMETER AND MODIFY ITS VALUE
        this.sqlDataSource1.Parameters[0].Value = report.Parameters["ManagerID"].Value;
    
        // Set the SqlDataSource component as it's DataSource
        report.DataSource = this.sqlDataSource1;
    }
    

    Since your parameter is multi-value you will need to create an IEnumerable. Then you can add the values of the parameter that the user selected to the IEnumerable. Then check to see if the user selected "Contract", and if not then add it to the list. Finally add the IEnumerable to the data source's parameter's value property.