Reporting

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

    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:

    CopyXML
    <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:

    CopyXML
    <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

CopyC#
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;
    }
}
CopyVB.NET
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then
        Dim typeReportSource As New Telerik.Reporting.TypeReportSource()
        typeReportSource.TypeName = "ListBoundReport, VB.ReportLibrary"
        ReportViewer1.ReportSource = typeReportSource
        ReportViewer1.RefreshReport()
    End If
End Sub

See Also