Reports
Changing Default Report Template

The Report action is interpreted by the application framework as a request to produce a report document in Adobe PDF, Microsoft Word, Microsoft Excel, or TIFF format. The framework uses Microsoft Report Viewer for that purpose. The Viewer requires a report definition in RDLC format and a dataset to produce the output.

The application framework includes a standard report template file written in XSLT. This report template is applied to a data controller file to produce a report definition in RDLC format when the Report action is handled by the framework. By default, the report template will be generated at run-time using report font, label, and orientation specified for the view.

The picture below shows a report created from Orders controller using the default report template.

Report created with the default report template of Orders controller.

The default report template file can be changed – the customizations will be applied to all non-custom reports.

Let’s add a copyright message at the bottom of all reports.

Start the web application generator, click on the project name, and press Develop to open the project in Visual Studio.

In the Solution Explorer, double-click on ~\Reports\Template.xslt to open the file.

Report template file selected in Visual Studio's 'Solution Explorer'.

Press Ctrl+I and type “PageFooter” to find the footer section. Make the highlighted changes:

<PageFooter>
  <PrintOnFirstPage>true</PrintOnFirstPage>
  <ReportItems>
    <Textbox Name="FooterPrintedInfoTextBox">
      <rd:DefaultName>textbox7</rd:DefaultName>
      <Width>4.125in</Width>
      <Top>0in</Top>
      <Style>
        <VerticalAlign>Bottom</VerticalAlign>
        <PaddingLeft>2pt</PaddingLeft>
        <PaddingRight>2pt</PaddingRight>
        <PaddingTop>2pt</PaddingTop>
        <PaddingBottom>2pt</PaddingBottom>
      </Style>
      <ZIndex>1</ZIndex>
      <CanGrow>true</CanGrow>
      <Paragraphs>
        <Paragraph>
          <TextRuns>
            <TextRun>
              <Value>
                <xsl:text>="© 2012 Code On Time LLC. ^PrintedOn^Printed on^PrintedOn^ " 
                  &amp; CStr(Now())</xsl:text>
                <xsl:text> &amp; IIf(CountRows("</xsl:text>
                <xsl:value-of select="@name"/>
                <xsl:text>") > 1, " (" &amp; CountRows("</xsl:text>
                <xsl:value-of select="@name"/>
                <xsl:text>") &amp; " ^Items^items^Items^)", "")</xsl:text>
              </Value>

Save the file and switch to the web browser. Navigate to any page that has a controller on it, and activate the Report | PDF Document action on the action bar. The copyright information is now displayed on the left side of the page footer.

Report created from default report template now has copyright information displayed in the bottom left corner.

Multiple XSLT report templates can be created. The name of a custom report template with full extension can be specified as the command argument of a Report action or as a value of _template option in the Data property of the action.