共用方式為


Web Form Viewer 的報表 Web 服務繫結選項

在 Web 應用程式使用報表 Web 服務之前,必須先將報表 Web 服務繫結到 Web Form Viewer。下一節將以不同的案例來說明將報表 Web 服務繫結到 Web Form Viewer 的方法。

案例 1:報表 Web 服務

假設以下條件存在,而且可將 Crystal Report 當成報表 Web 服務使用:

  • 此報表 (My Report.rpt) 可以當成報表 Web 服務 (My Report.asmx) 使用。
  • 已將 MyReportService.asmx 發行到 Web 伺服器 MyServer 上的 ServerProject 專案中。

在 Visual Basic 或 C# 應用程式中

  • 在用戶端上,您已在本機伺服器 https://localhost 上建立了一個 ASP.NET Web 應用程式專案,名稱為 MyProject。
  • 您已在 MyProject 的 Web Form (WebForm1.aspx) 中插入一個 Web Form Viewer,名稱為 CrystalReportViewer1

在 C++ 應用程式中

  • 您已建立了一個 Managed C++ 專案,名稱為 MyProject。
  • 您已在 MyProject 的 MyProject.cpp 中加入一個 Web Form Viewer,名稱為 CrystalReportViewer1

依報表 Web 服務繫結

您可以透過 [程式碼] 檢視來指定 ReportSource 屬性。

[Visual Basic]

CrystalReportViewer1.ReportSource = 
"http://MyServer/ServerProject/My ReportService.asmx"

[C#]

CrystalReportViewer1.ReportSource = 
"http://MyServer/ServerProject/My ReportService.asmx";

[C++]

CrystalReportViewer1->ReportSource = 
"http://MyServer/ServerProject/My ReportService.asmx";

[VJ#]

CrystalReportViewer1.set_ReportSource("http://MyServer/ServerProject/My ReportService.asmx");

案例 2:已加入至專案的報表 Web 服務

假設以下條件存在:

  • 此報表 (My Report.rpt) 可以當成報表 Web 服務 (My Report.asmx) 使用。
  • 已將 MyReportService.asmx 發行到 Web 伺服器 MyServer 上的 ServerProject 專案中。
  • 在用戶端上,您已在本機伺服器 https://localhost 上建立了一個 C# 的 Web 應用程式專案,名稱為 MyProject。
  • 您已在 MyProject 的 Web Form (WebForm1.aspx) 中插入一個 Web Form Viewer,名稱為 CrystalReportViewer1
  • 在用戶端上,您已經將報表 Web 服務加入 MyProject 中。

將報表 Web 服務加入至用戶端專案時會建立一個 Proxy 類別。您可以使用 Proxy 物件的執行個體,將 My Report.rpt 的報表 Web 服務繫結至 Web Form Viewer。

注意    在 C++ 專案中加入及繫結報表 Web 服務需要用程式碼。沒有可使用的 C++ 範例。

依 Proxy 物件繫結

在 WebForm1.aspx 的 [程式碼] 檢視中的 InitializeComponent() 呼叫之後指定:

[Visual Basic]

CrystalReportViewer1.ReportSource = _
new MyProject.localhost.My_ReportService()

[C#]

CrystalReportViewer1.ReportSource = 
new MyProject.localhost.My_ReportService();

[C++] 沒有可使用的 C++ 範例。若要知道在 C# 或 Visual Basic 應用程式中的做法,請按一下畫面左上角的 [語言篩選條件] 按鈕。

[VJ#]

CrystalReportViewer1.set_ReportSource( 
new localhost.My_ReportService());

案例 3:已加入至 Web Form 的 Crystal Enterprise 報表

假設以下條件存在:

依 Crystal Enterprise 報表物件繫結

您可以透過 WebForm1.aspx 的 [屬性] 視窗或 [程式碼] 檢視指定 ReportSource 屬性,將 MyCEReport.rpt 的報表 Web 服務繫結至 Web Form Viewer。

透過屬性視窗

  1. 請到 WebForm1.aspx 的 [設計] 索引標籤中。選取 Web Forms Viewer。

  2. 在 [屬性] 視窗中,按一下 DataBindings 屬性右邊的方形按鈕。這會叫用 [CrystalReportViewer1 DataBindings] 對話方塊。

  3. 在 [CrystalReportViewer1 DataBindings] 對話方塊的左邊窗格中,選取 [可繫結的屬性] 之下的 ReportSource。

  4. 按一下 [簡單繫結]。展開 [頁面] 節點,並從樹狀結構中選取 enterpriseReport1。按一下 [確定]。

  5. 在 WebForm1.aspx 中的 InitializeComponent() 呼叫之後,新增以下這一行:

    CrystalReportViewer1.DataBind();
    

    注意    在 C++ 專案中加入及繫結報表 Web 服務需要用程式碼。沒有可使用的 C++ 範例。

透過程式碼檢視

  1. 將 CrystalDecisions.ReportSource 和 CrystalDecisions.Shared 的參考加入專案。

  2. 透過 WebForm1.aspx 的 [程式碼] 檢視,在 InitializeComponent() 呼叫之後指定 ReportSource 屬性,將 Crystal Enterprise 報表物件繫結至 Web Form Viewer:

    CrystalReportViewer1.ReportSource = enterpriseReport1
    [C#]CrystalReportViewer1.ReportSource = enterpriseReport1;
    

    [C++] 沒有可使用的 C++ 範例。若要知道在 C# 或 Visual Basic 應用程式中的做法,請按一下畫面左上角的 [語言篩選條件] 按鈕。

    CrystalReportViewer1.set_ReportSource( enterpriseReport1);
    

案例 4:已加入至 Web Form 的伺服器檔案報表

假設以下條件存在:

依伺服器檔案報表物件繫結

您可以透過 WebForm1.aspx 中的 [屬性] 視窗或程式碼,將伺服器檔案報表 MyServerFileReport.rpt 繫結至 Web Form Viewer。

透過屬性視窗

  1. 請到 WebForm1.aspx 的 [設計] 索引標籤中。選取 Web Forms Viewer。

  2. 在 [屬性] 視窗中,按一下 DataBindings 屬性右邊的方形

  3. 按鈕。這會叫用 [CrystalReportViewer1 DataBindings] 對話方塊。

  4. 在 [CrystalReportViewer1 DataBindings] 對話方塊的左邊窗格中,選取 [可繫結的屬性] 之下的 ReportSource。

  5. 按一下 [簡單繫結]。展開 [頁面] 節點,並從樹狀結構中選取 serverFileReport1。按一下 [確定]。

  6. 在 WebForm1.aspx 原始程式檔中的 InitializeComponent() 呼叫之後,加入以下這一行:

    CrystalReportViewer1.DataBind()
    [C#]CrystalReportViewer1.DataBind();
    

    [C++] 在 C++ 專案中加入及繫結報表 Web 服務需要用程式碼。沒有可使用的 C++ 範例。若要知道在 C# 或 Visual Basic 應用程式中的做法,請按一下畫面左上角的 [語言篩選條件] 按鈕。

    CrystalReportViewer1.DataBind();
    

透過程式碼檢視

  1. 將 CrystalDecisions.ReportSource 和 CrystalDecisions.Shared 的參考加入專案。

  2. 透過 WebForm1.aspx 的 [程式碼] 檢視,在 InitializeComponent() 呼叫之後指定 ReportSource 屬性,將伺服器檔案報表物件繫結至 Web Form Viewer:

    CrystalReportViewer1.ReportSource = serverFileReport1
    [C#]CrystalReportViewer1.ReportSource = serverFileReport1;
    

    [C++] 在 C++ 專案中加入及繫結報表 Web 服務需要用程式碼。沒有可使用的 C++ 範例。若要知道在 C# 或 Visual Basic 應用程式中的做法,請按一下畫面左上角的 [語言篩選條件] 按鈕。

    CrystalReportViewer1.set_ReportSource( serverFileReport1);
    

請參閱

在執行階段繫結報表與檢視器