Showing results for 
Search instead for 
Did you mean: 

To open SubReport Using

Former Member
0 Kudos

I am having a main report with 3 subreports. Through link button i need to open the subreport.

I got the subreport name. but i am not able to open the subreport. Please help to solve this

My code looks like this

crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos


possible code in CS for VS2005 looks like this:

The interface in VB should be the same


//File Name: CS_AddSortfieldsMainSub_inproc.sln

//Created: March 13, 2008

//Author ID: FLI


//Purpose: This C# .NET sample Windows application demonstrates

// how to add a sortfield to a main- and subreport

// using unmanaged inproc RAS.

// The app will :

// - add the Order ID as sortfield to the mainreport

// and sort in ascending order.

// - add the Product ID as sortfield to the subreport

// and sort in descending order.


// Note this is available without a dedicated RAS with SP2 for XI R2


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.ReportAppServer.Controllers;

using CrystalDecisions.ReportAppServer.ClientDoc;

using CrystalDecisions.ReportAppServer.DataDefModel;

namespace CS_AddSortfieldsMainSub_inproc


public partial class Form1 : Form


// CR Declarations

ReportDocument boReportDocument = new ReportDocument();

ISCDReportClientDocument boReportClientDocument;

DatabaseFieldDefinition boDatabaseFieldDefinition;

Sort boSortField = new Sort();

Sort boSubRepSortField = new Sort();

string mySortDir;

public Form1()



//BO added

// load the RPT file



// main report


//Access the ReportClientDocument in the ReportDocument (EROM bridge)

boReportClientDocument = boReportDocument.ReportClientDocument;

DataDefController dataDefController = boReportClientDocument.DataDefController;

Fields fields = boReportClientDocument.DataDefController.DataDefinition.ResultFields;

// define sorting for main report

boSortField.SortField = fields[0]; // index for field name -> Order ID

boSortField.Direction = CrSortDirectionEnum.crSortDirectionAscendingOrder;

// add this filed name to the SortList at index 0

dataDefController.SortController.Add(0, boSortField);


// sub report


SubreportClientDocument boSubReportClientDocument = boReportClientDocument.SubreportController.GetSubreport("OrderDetailsSub");

DataDefController SubrepdataDefController = boSubReportClientDocument.DataDefController;

Fields Subrepfields = boSubReportClientDocument.DataDefController.DataDefinition.ResultFields;

// define sorting

boSubRepSortField.SortField = Subrepfields[0]; // index for field name -> Product ID

boSubRepSortField.Direction = CrSortDirectionEnum.crSortDirectionDescendingOrder;

// add this filed name to the SortList at index 0

SubrepdataDefController.SortController.Add(0, boSubRepSortField);

// show in reportviewer

crystalReportViewer1.ReportSource = boReportDocument;




Answers (0)