sjsm
附件中的示例工程展示了如何通过代码添加报表数据源:
- protected void Page_Load(object sender, EventArgs e)
- {
- GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("Rpx套打功能.rdlx")));
- #region 通过代码添加数据源
- // 创建并设置数据源
- GrapeCity.ActiveReports.PageReportModel.DataSource myDataSource = new GrapeCity.ActiveReports.PageReportModel.DataSource();
- myDataSource.Name = "DataSource1";
- myDataSource.ConnectionProperties.DataProvider = "DATASET";
- // 设置数据集
- GrapeCity.ActiveReports.PageReportModel.DataSet myDataSet = new GrapeCity.ActiveReports.PageReportModel.DataSet();
- GrapeCity.ActiveReports.PageReportModel.Query myQuery = new GrapeCity.ActiveReports.PageReportModel.Query();
- myDataSet.Name = "DataSet1";
- myQuery.DataSourceName = "DataSource1";
- myDataSet.Query = myQuery;
- // 添加字段
- GrapeCity.ActiveReports.PageReportModel.Field _field = new
- GrapeCity.ActiveReports.PageReportModel.Field("Col1", "Col1", null);
- myDataSet.Fields.Add(_field);
- _field = new GrapeCity.ActiveReports.PageReportModel.Field("Col2", "Col2", null);
- myDataSet.Fields.Add(_field);
- _field = new GrapeCity.ActiveReports.PageReportModel.Field("Col3", "Col3", null);
- myDataSet.Fields.Add(_field);
- // 将数据源和数据集绑定到报表中
- report.Report.DataSources.Add(myDataSource);
- report.Report.DataSets.Add(myDataSet);
- #endregion
- report.Document.LocateDataSource += new GrapeCity.ActiveReports.LocateDataSourceEventHandler(Document_LocateDataSource);
- WebViewer1.Report = report;
- }
- void Document_LocateDataSource(object sender, GrapeCity.ActiveReports.LocateDataSourceEventArgs args)
- {
- System.Data.DataTable dt = new System.Data.DataTable();
- dt.Columns.Add("Col1");
- dt.Columns.Add("Col2");
- dt.Columns.Add("Col3");
- dt.Rows.Add(1, 2, 3);
- args.Data = dt;
- }
复制代码 |