Dynamically passing parameter to DrillThrough report in RDLC - Part 2
Continueing with my earlier post on the RDLC and Drill Through reports, in this article we'll be checking the second method of passing parameters through filtering of report items.
The steps till completing the design of the reports are still going to remain the same. So please refer,
We'll be doing the code change only in the DrillThrough event handler code. Look at the below lines of code.
protected
void ReportViewer1_Drillthrough(object sender, Microsoft.Reporting.WebForms.DrillthroughEventArgse)
{
//Get the instance of the Target report, in our case the JumpFilterReport.rdlc.
LocalReport report = (LocalReport)e.Report;
//Create the instance for the EmpDeptHistoryDataSet which will
//hold the EmployeeDepartmentHistory table details.
EmpDeptHistoryDataSet ds = new EmpDeptHistoryDataSet();
//Making sure the dataset doesn't contain any constraints.
ds.EnforceConstraints =
false;
//Create a SQL Connection to the AdventureWorks database using Windows Authentication.
using (SqlConnection sqlconn = new SqlConnection("Data Source=.;Initial Catalog=Adventureworks;Integrated Security=SSPI"))
{
//Building the SQL query.
SqlDataAdapter adap = new SqlDataAdapter("select EmployeeID, DepartmentID, ShiftID from HumanResources.EmployeeDepartmentHistory", sqlconn);
//Executing the QUERY and filling the dataset with the Resultset.
adap.Fill(ds,
"EmployeeDepartmentHistory");
}
report.DataSources.Add(
new ReportDataSource("EmpDeptHistoryDataSet_EmployeeDepartmentHistory", ds.EmployeeDepartmentHistory));
}
Finally, run the project, You'll see MainReport rendering in the ReportViewer control.
Click on any of the EmployeeID and you'll see the JumpFilterReport displayed for the selected EmployeeID.
If you carefully look at the difference between what we saw in the Part - 1 and now is, the QUERY that is executed in this sample is an unfiltered one. The filtering is done at the report level by adding the filter on table1 in the report "JumpFilterReport.rdlc". Refer the below pictures.
Picture 1: Definiting the paramter for the report.
Picture 2: Defining the filter in table1 based on the parameter defined in Pciture 1.
The paramter is being passed from the main report "MainReport.rdlc" as part of the navigation which we configured for the textbox7 in table1 as shown below,
Based on the requirement, you can choose either one of the option. But if you're too concerned about the performance, then my recommendation would be to follow Part - 1.
That pretty much concludes our sample. I’ve uploaded the sample please change the connections string values in the web.config and in the Default.aspx.cs files and try executing the report. Happy programming!!.
HTH!
Selva.
[All the Posts are AS-IS with no warranties]