In the report viewing application you can populate the values of
ReportParameters collection members prior to displaying the report.
CopyC#
Report1 report = new Report1();
report.ReportParameters["ManagerID"].Value = "123";
CopyVB.NET
Dim report As New Report1()
report.ReportParameters("ManagerID").Value = "123"
At runtime you can access the report parameters through the
Report..::.Parameters
dictionary. Each Parameter
object contains resolved available values, current value and label.
The label returns the currently selected DisplayMember
from the available values (if available values are defined).
Note | |
Prior to version 2010 Q1 the processing report exposes a dictionary
containing only the current values of the report parameters.
|
Example:
- Create a Telerik Report
- Use the instructions from the How to: Connect to a SQL Server Database Using Stored Procedure
article to bind to the uspGetManagerEmployees stored procedure from the AdventureWorks table.
- Leave the Value for the @ManagerID data source parameter empty and finish the wizard.
- Create the following layout for the report
- Add a report
parameter and name it ManagerID.
- Change its Type to Integer.
- Set its Visible property to True.
- Expand the AvailableValues and bind it to
SqlDataSource component with
the following query:
CopySQL
SELECT M.ManagerID, C.FirstName + ' ' + C.LastName AS Name
FROM (SELECT DISTINCT ManagerID
FROM HumanResources.Employee) AS M INNER JOIN
HumanResources.Employee AS E ON M.ManagerID = E.EmployeeID INNER JOIN
Person.Contact AS C ON E.ContactID = C.ContactID
- Set the ValueMember to = Fields.ManagerID.
- Set the DisplayMember to = Fields.Name.
- Add grouping for the report with = Fields.ManagerID as grouping expression.
- Wire the NeedDataSource event of the report.
- In the report.cs file set the DataSource property
to null (Nothing in VB.NET)
so that NeedDataSource event is fired.
- Add the following code to the NeedDataSource event handler:
CopyC#
private void Report1_NeedDataSource(object sender, System.EventArgs e)
{
Telerik.Reporting.Processing.Report report = (Telerik.Reporting.Processing.Report)sender;
this.sqlDataSource1.Parameters[0].Value = report.Parameters["ManagerID"].Value;
report.DataSource = this.sqlDataSource1;
}
CopyVB.NET
Private Sub Report1_NeedDataSource(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.NeedDataSource
Dim report As Telerik.Reporting.Processing.Report = DirectCast(sender, Telerik.Reporting.Processing.Report)
Me.sqlDataSource1.Parameters(0).Value = report.Parameters("ManagerID").Value
report.DataSource = Me.sqlDataSource1
End Sub
- Display the Report
in a report viewer.
- Select a parameter from the available values in the parameter editor
and click Preview.