Displaying Reports and Documents
The C1ReportViewer control can show any report or document that can be generated by C1Report. This is specified via the following three public properties on the viewer:
• FileName: Gets or sets the report or document file name.
• ReportName: Gets or sets the name of the report.
• Document: Gets or sets the report or document to view.
The FileName and ReportName properties can be set at design time. The Document property is a run time only property. Note that if it is assigned to a non-null value, the Document property overrides any FileName and ReportName values. The types allowed for the Document property are from C1.C1Report.2.dll and can be:
• C1.C1Report.C1Report
• C1.C1Preview.C1PrintDocument
The following kinds of documents can be shown by the C1ReportViewer control:
• A C1Report loaded from an XML file (such as the reports in the CommonTasks.xml sample shipped with C1Report). To specify this type of document, the FileName and ReportName properties should be assigned, while leaving the Document property empty. For example:
C1ReportViewer1.FileName = "~/CommonTasks.xml"
C1ReportViewer1.ReportName = "Greenbar Report"
• C#
C1ReportViewer1.FileName = "~/CommonTasks.xml";
C1ReportViewer1.ReportName = "Greenbar Report";
• A C1Report generated in memory by user code (such as in the Page_Load event). For example:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim rep As C1.C1Report.C1Report = Me.C1ReportViewer1.CreateC1Report()
rep.Load(MapPath("~/CommonTasks.xml"), "Greenbar Report")
Me.C1ReportViewer1.Document = rep
End Sub
• C#
protected void Page_Load(object sender, EventArgs e)
{
C1.C1Report.C1Report rep = this.C1ReportViewer1.CreateC1Report();
rep.Load(MapPath("~/CommonTasks.xml"), "Greenbar Report");
this.C1ReportViewer1.Document = rep;
}
• A C1PrintDocument loaded from a C1D or C1DX file. To specify this, the FileName property should be set to the name of the .c1d/.c1dx file, for example:
C1ReportViewer1.FileName = "~/MyDocument.c1dx"
• C#
C1ReportViewer1.FileName = "~/MyDocument.c1dx";
• A C1PrintDocument generated in memory by user code, for example:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim doc As C1PrintDocument = Me.C1ReportViewer1.CreateC1PrintDocument()
doc.Body.Children.Add(New RenderText("Hello World!"))
Me.C1ReportViewer1.Document = doc
End Sub
• C#
protected void Page_Load(object sender, EventArgs e)
{
C1PrintDocument doc = this.C1ReportViewer1.CreateC1PrintDocument();
doc.Body.Children.Add(new RenderText("Hello World!"));
this.C1ReportViewer1.Document = doc;
}
• An RDL report loaded from an RDL report definition file. For example:
C1ReportViewer1.FileName = "~/MyRdlReport.rdl"
• C#
C1ReportViewer1.FileName = "~/MyRdlReport.rdl";
|