首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

VS2005 + Crystal Report 開發 Web 應用 (6) - 繫結報表至 Viewer 與集合資料填充

     編輯:關於C語言

步驟 1:報表繫結至 CrystalReportViewer

  1. 切換至 Default.aspx.cs 程式碼後置
  2. 引用命名空間:using System.Collections;
  3. 類別層級宣告:
     private ArrayList stockValues;
     private ReportDocument stockObjectsReport;
  4. ConfigureCrystalReports() 方法實作:
     • string reportPath = Server.MapPath("StockObjects.rpt");
     • stockObjectsReport = new ReportDocument();
     • stockObjectsReport.Load(reportPath);
     • stockObjectsReport.SetDataSource(stockValues);
     • crystalReportViewer.ReportSource = stockObjectsReport;

ReportDocument 屬 CrystalDecisions.CrystalReports.Engine 命名空間,載入報表後可透過 SDK 存取。

步驟 2:程式化填充物件集合

PopulateStockValuesArrayList() 輔助方法

public void PopulateStockValuesArrayList()
{
    if (Session["stockValues"] == null)
    {
        stockValues = new ArrayList();
        stockValues.Add(new Stock("AWRK", 1200, 28.47));
        stockValues.Add(new Stock("CTSO", 800, 128.69));
        stockValues.Add(new Stock("LTWR", 1800, 12.95));
        Session["stockValues"] = stockValues;
    }
    else
    {
        stockValues = (ArrayList)Session["stockValues"];
    }
}
  • 在 ConfigureCrystalReports() 首行呼叫此方法
  • 建置專案,啟用偵錯(首次需修改 Web.config)
  • 瀏覽器顯示三筆預設資料

步驟 1:報表繫結至 CrystalReportViewer

  1. 切換至 Default.aspx.cs 程式碼後置
  2. 引用命名空間:using System.Collections;
  3. 類別層級宣告:
     private ArrayList stockValues;
     private ReportDocument stockObjectsReport;
  4. ConfigureCrystalReports() 方法實作:
     • string reportPath = Server.MapPath("StockObjects.rpt");
     • stockObjectsReport = new ReportDocument();
     • stockObjectsReport.Load(reportPath);
     • stockObjectsReport.SetDataSource(stockValues);
     • crystalReportViewer.ReportSource = stockObjectsReport;

ReportDocument 屬 CrystalDecisions.CrystalReports.Engine 命名空間,載入報表後可透過 SDK 存取。

步驟 2:程式化填充物件集合

PopulateStockValuesArrayList() 輔助方法

public void PopulateStockValuesArrayList()
{
    if (Session["stockValues"] == null)
    {
        stockValues = new ArrayList();
        stockValues.Add(new Stock("AWRK", 1200, 28.47));
        stockValues.Add(new Stock("CTSO", 800, 128.69));
        stockValues.Add(new Stock("LTWR", 1800, 12.95));
        Session["stockValues"] = stockValues;
    }
    else
    {
        stockValues = (ArrayList)Session["stockValues"];
    }
}
  • 在 ConfigureCrystalReports() 首行呼叫此方法
  • 建置專案,啟用偵錯(首次需修改 Web.config)
  • 瀏覽器顯示三筆預設資料
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved