在公司开发,使用到ReportView技术,写下自己的经验。
1.在工具箱中找到 ReportViewer,ScriptManager放到test.aspx页面。
如果找不到报表项,请参考http://www.cnblogs.com/worf/p/5714455.html
2.添加数据集 DataSet.xsd
在数据集中添加DataTable,添加查询的列,列名要和数据库中的列(字段)对应。
3.添加报表Report.rdlc
4.绑定数据
在这里绑定数据使用的是动态绑定。
1 private void getDateBind() 2 { 3 //获得路径 4 string req_url = this.Request.Url.ToString(); 5 string currentPath = ""; 6 int pos = req_url.LastIndexOf("/"); 7 if (pos > 0) 8 { 9 currentPath = req_url.Substring(0, pos + 1);//给报表文本框添加url 10 } 11 DataSet ds = BuildingDetails.GetIndustryHYData(time1, time2, buildingId, industryId);//从数据库中查询的数据 12 totalCount.InnerText = ds.Tables[0].Rows.Count.ToString(); 13 rvBuildingDetail_IndustryHY.LocalReport.DataSources.Clear(); 14 rvBuildingDetail_IndustryHY.LocalReport.DataSources.Add(new ReportDataSource("BuildingDetail_IndustryHY", ds.Tables[0])); 15 rvBuildingDetail_IndustryHY.AsyncRendering = true; 16 rvBuildingDetail_IndustryHY.InteractivityPostBackMode = InteractivityPostBackMode.AlwaysSynchronous; 17 rvBuildingDetail_IndustryHY.ShowToolBar= true;//获取或设置一个指示工具栏在控件上是否可见的值。默认为true 18 rvBuildingDetail_IndustryHY.LocalReport.EnableHyperlinks = true;//指示在报表包含超链接操作时是否可以呈现 19 rvBuildingDetail_IndustryHY.HyperlinkTarget = "_self";//在相同的框架中打开被链接文档 20 rvBuildingDetail_IndustryHY.LocalReport.ReportPath = @"BuildingDetail\rdlc\BuildingDetail_IndustryHY.rdlc";//获取或设置本地报表的本地文件系统路径 21 rvBuildingDetail_IndustryHY.LocalReport.ReportEmbeddedResource = "BuildingDetail_IndustryHY.rdlc";//获取或设置报表嵌入资源的名称 22 23 //设置参数 24 ReportParameter rpCurrentPath = new ReportParameter("url", currentPath); 25 ReportParameter rpTime1 = new ReportParameter("time1", time1); 26 ReportParameter rpTime2 = new ReportParameter("time2", time2); 27 ReportParameter rpIndustryId = new ReportParameter("industryId", industryId); 28 ReportParameter rpBuildingId = new ReportParameter("buildingId", buildingId); 29 rvBuildingDetail_IndustryHY.LocalReport.SetParameters(new ReportParameter[] { rpCurrentPath, rpCurrentPath, rpTime1, rpTime2, rpIndustryId, rpBuildingId }); 30 }
到此,整个流程完成。