# C1.Report.Field.Subreport

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_Report_Field_Subreport_" data-uid="C1.Report.Field.Subreport*">Subreport Property
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_Report_Field_Subreport_" data-uid="C1.Report.Field.Subreport*"></a>
<h4 id="C1_Report_Field_Subreport" data-uid="C1.Report.Field.Subreport">Subreport</h4>
<div class="markdown level1 summary"><p>Gets or sets a reference to another report to be rendered within the field (a <i>subreport</i>).</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">[C1Category(&quot;Special&quot;)]
[C1Description(&quot;SubreportField.Subreport&quot;, &quot;Specifies another C1FlexReport object to be rendered within this field.&quot;)]
public FlexReport Subreport { get; set; }</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">&lt;C1Category(&quot;Special&quot;)&gt;
&lt;C1Description(&quot;SubreportField.Subreport&quot;, &quot;Specifies another C1FlexReport object to be rendered within this field.&quot;)&gt;
Public Property Subreport As FlexReport</code></pre>
</div>
<h5 id="C1_Report_Field_Subreport_remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>A subreport is a report that is inserted in another report. Subreports are useful when you want to combine 
several reports into one. For example, you may have a main report that integrates several subreports into a single 
main report. Or you can use the main report to show detailed information and use subreports to show summary data 
at the beginning of each group.</p>
<p>For some real-world examples, check the "Sales By Category" and "Sales By Year" reports in the NWIND.XML
sample that ships with the control.</p>
<p>To define a field as a subreport, you should start by loading the subreport, then assign the subreport 
control to the field's <a class="xref" href="C1.Report.Field.Subreport.html#C1_Report_Field_Subreport">Subreport</a> property.</p>
<p>Next, link the subreport to the main report using the subreport field's <a class="xref" href="C1.Report.Field.Text.html#C1_Report_Field_Text">Text</a> property (this is 
analogous to setting the <b>LinkChildFields/LinkMasterFields</b> properties in a Microsoft  Access subreport). The 
<b>Text</b> property in a subreport field is used as a filter. It specifies which records in the source recordset 
should be used to render the subreport based on the current record for the main report.</p>
<p>When the main report is being rendered and reaches the subreport field, the <b>Text</b> expression is evaluated 
and the result is uses as a filter condition for the subreport.</p>
<p>Building the link expression is not difficult, but it is a little tricky because it requires you to create a 
string that contains quotes, and these internal quotes must be doubled (written as "").</p>
<p>If you are creating reports using the Report Designer, you don't have to worry about building the link expressions 
in code. Instead, right-click the subreport field and select the <b>Link Subreport...</b> menu. This will show a dialog 
where you can select the master and detail fields. When you click OK, the Report Designer will build the link expression 
and assign it to the <b>Text</b> property of the subreport field automatically.</p>
<p>Subreport fields usually have the <a class="xref" href="C1.Report.FieldBase.AutoHeight.html#C1_Report_FieldBase_AutoHeight">AutoHeight</a> property set to <a class="xref" href="C1.Report.AutoSizeBehavior.html#C1_Report_AutoSizeBehavior_CanGrow">CanGrow</a>, so the subreport field can expand to 
include all its records.</p>
<p>Subreports may contain other subreports. There's no set limit for the depth of report nesting you can have. 
However, there must be no circular references to reports. In other words, a report cannot contain a reference to itself 
as a subreport.</p>
</div>
<h5 id="C1_Report_Field_Subreport_examples">Examples</h5>
<pre><code class="lang-csharp">// load subreport and assign it to a field in the main report
string sSub = "Sales By Category Subreport";
c1Sub.Load("NWIND.XML", sSub);
c1rMain.Fields[sSub].Subreport = c1Sub;

// set up connection between main report and subreport
c1rMain.Fields[sSub].Calculated = true;
c1rMain.Fields[sSub].Text = "\"CategoryName = '\" &amp; [CategoryName] &amp; \"'\"";</code></pre>

</div>
