ReportView报表开发记录(一)

时间:2022-02-22 17:57:24

在公司开发,使用到ReportView技术,写下自己的经验。

1.在工具箱中找到 ReportViewer,ScriptManager放到test.aspx页面。

如果找不到报表项,请参考http://www.cnblogs.com/worf/p/5714455.html

ReportView报表开发记录(一)

2.添加数据集 DataSet.xsd

ReportView报表开发记录(一)

在数据集中添加DataTable,添加查询的列,列名要和数据库中的列(字段)对应。

3.添加报表Report.rdlc

ReportView报表开发记录(一)

4.绑定数据

在这里绑定数据使用的是动态绑定。

  private void getDateBind()
{
//获得路径
string req_url = this.Request.Url.ToString();
string currentPath = "";
int pos = req_url.LastIndexOf("/");
if (pos > )
{
currentPath = req_url.Substring(, pos + );//给报表文本框添加url
}
DataSet ds = BuildingDetails.GetIndustryHYData(time1, time2, buildingId, industryId);//从数据库中查询的数据
totalCount.InnerText = ds.Tables[].Rows.Count.ToString();
rvBuildingDetail_IndustryHY.LocalReport.DataSources.Clear();
rvBuildingDetail_IndustryHY.LocalReport.DataSources.Add(new ReportDataSource("BuildingDetail_IndustryHY", ds.Tables[]));
rvBuildingDetail_IndustryHY.AsyncRendering = true;
rvBuildingDetail_IndustryHY.InteractivityPostBackMode = InteractivityPostBackMode.AlwaysSynchronous;
rvBuildingDetail_IndustryHY.ShowToolBar= true;//获取或设置一个指示工具栏在控件上是否可见的值。默认为true
rvBuildingDetail_IndustryHY.LocalReport.EnableHyperlinks = true;//指示在报表包含超链接操作时是否可以呈现
rvBuildingDetail_IndustryHY.HyperlinkTarget = "_self";//在相同的框架中打开被链接文档
rvBuildingDetail_IndustryHY.LocalReport.ReportPath = @"BuildingDetail\rdlc\BuildingDetail_IndustryHY.rdlc";//获取或设置本地报表的本地文件系统路径
rvBuildingDetail_IndustryHY.LocalReport.ReportEmbeddedResource = "BuildingDetail_IndustryHY.rdlc";//获取或设置报表嵌入资源的名称 //设置参数
ReportParameter rpCurrentPath = new ReportParameter("url", currentPath);
ReportParameter rpTime1 = new ReportParameter("time1", time1);
ReportParameter rpTime2 = new ReportParameter("time2", time2);
ReportParameter rpIndustryId = new ReportParameter("industryId", industryId);
ReportParameter rpBuildingId = new ReportParameter("buildingId", buildingId);
rvBuildingDetail_IndustryHY.LocalReport.SetParameters(new ReportParameter[] { rpCurrentPath, rpCurrentPath, rpTime1, rpTime2, rpIndustryId, rpBuildingId });
}
到此,整个流程完成。