Telerik Reporting R3 2016

How to: Add report viewer to a web page

Note Note

This is a legacy report viewer and for new projects our recommendation is to use the latest web forms report viewer - HTML5 Web Forms Report Viewer

Assign report to the viewer in design time

To use Telerik Reports in web application, you need the Web report viewer:

  1. Drag the ReportViewer control from the Toolbox to the design surface of a web form.

    By doing so, the ReportViewer control would register automatically the http handler it needs to function properly in the web.config file of the web application/site.

    Note Note

    The http handler is automatically registered in the web.config only when the report viewer control is dropped from the Toolbox to the design surface of a web form. If you drop the report viewer in the text editor (source view) or add it to the web form programatically, you should manually register the http handler using the xml markup below, where x.x.x.x is your Telerik Reporting assembly version.

    In the <system.web>\<httpHandlers> section:

    <system.web>
    ....
      <httpHandlers>
            <add path="Telerik.ReportViewer.axd" verb="*" type="Telerik.ReportViewer.WebForms.HttpHandler, Telerik.ReportViewer.WebForms, Version=x.x.x.x, Culture=neutral, PublicKeyToken=a9d7983dfcc261be"/>
      </httpHandlers>
    ....
    </system.web>

    In the <system.webServer>\<handlers> section:

    <system.webServer>
        <handlers>
          <add name="Telerik.ReportViewer.axd_*" path="Telerik.ReportViewer.axd" verb="*" type="Telerik.ReportViewer.WebForms.HttpHandler, Telerik.ReportViewer.WebForms, Version=x.x.x.x, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" preCondition="integratedMode"/>
        </handlers>
        <validation validateIntegratedModeConfiguration="false"/>
    </system.webServer>

  2. Add reference to the class library that contains your reports in the web application/site.
  3. Build the application
  4. Set the ReportSource for the report viewer. For more information, see How to: Set ReportSource for Report Viewers.

Assign report to the viewer programatically

In the Page_Load event handler you create an instance report source and set its ReportDocument property to a report instance. Next assign the instance report source to the ReportSource property of the viewer.

Example

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        var typeReportSource = new Telerik.Reporting.TypeReportSource();
        typeReportSource.TypeName = "Telerik.Reporting.Examples.CSharp.ListBoundReport, CSharp.ReportLibrary";
        this.ReportViewer1.ReportSource = typeReportSource;
    }
}

See Also