1、web.config 里 printcontrol.cab是activex模式需要的控件,网上随处可见,需要在配置里指定下载位置
<sectionGroup name="businessObjects">
<sectionGroup name="crystalReports">
<section name="printControl" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Custom=null" />
</sectionGroup>
</sectionGroup>
</configSections>
<businessObjects>
<crystalReports>
<printControl>
<add key="url " value="http://*.*.*.*/hys/cab/printcontrol.cab" />
</printControl>
</crystalReports>
</businessObjects>
2、aspx里
<%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true"
PrintMode="ActiveX" />
3、cs里
把报表里需要显示的字段打包成一个用于绑定报表的实体类 在新建的报表上绑定这个类,并设计好字段显示的位置
ReportDocument myReport = new ReportDocument();
string reportPath = Server.MapPath("~/crInfo.rpt");
myReport.Load(reportPath);
MeetingInfo mi = new MeetingInfo();
.......数据库操作,读取数据填充实体类
List<MeetingInfo> miList = new List<MeetingInfo>();
miList.Add(mi);
myReport.SetDataSource(miList);
this.CrystalReportViewer1.ReportSource = myReport;
this.CrystalReportViewer1.DataBind();