1. Use the previous report data source to create a primary report and a subreport (subreport)
2. Set drilling parameters in the subreport table, that is, Department.
3. Set the main report drilling link.
In the "operations" column of the text box. Enable the "go to report" button for the hyperlink and select a subreport.
Then, add a parameter, that is, select the drilling parameter of the subreport and select the passed field in the value.
4. Modify the subreport data source (this step can be omitted if it is only ported to a web project. SSRS cannot be ignored)
In this case, the drill-down report can be previewed. But in order to port it to a web project, continue...
5. In web projects, drilling reports must implement Drillthrough events.
View Code
/// <Summary> /// subreport data source /// </summary> /// <param name = "para"> Drilling Parameter </param> /// <returns> data source table </returns> private DataTable GetChildData (string para) {DataTable dt = new DataTable (); string text = "select * from HumanResources. vEmployeeDepartment where Department = '"+ para +"' "; dt = SqlHelper. executeDataset (BaseCommon. connectionString, CommandType. text, text ). tables [0]; return dt;} protected vo Id rptvContainer_Drillthrough (object sender, DrillthroughEventArgs e) {LocalReport Report = (LocalReport) e. report; Report. reportPath = Report. reportPath. remove (Report. reportPath. length-1); // Report. dataSources. add (new ReportDataSource ("DataSet1", // GetChildData (Report. originalParametersToDrillthrough [0]. values [0]); ReportParameterInfoCollection co = Report. getParameters (); if (co. count> 0) {For (int I = 0; I <co. Count; I ++) {if (! String. isNullOrEmpty (co [I]. values [0]) {Report. dataSources. add (new ReportDataSource ("DataSet1", GetChildData (co [I]. values [0]) ;}} Report. refresh ();}
NOTE: If drilling parameters are only applicable, you can use the OriginalParametersToDrillthrough indexer. The GetParameters method is recommended in msdn. This method gets a set of all parameters of the report.
Because the report object obtained by web project is rdlc by default, but the report is rdl, the last bit can be taken to match the actual path.
The main and subreports are as follows.