Assign report to the viewer in design time
To use Telerik Reports in web application, you need the Web report viewer:
- 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 handlers it needs to function
properly in the web.config file of the web application/site.
Namely 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>
and in the <system.webServer>\<handlers> section as well (IIS 7 only):
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>
- Add reference to the class library that contains your reports in the web application/site.
- Build the application
- Set the Report property of the viewer using the drop down list in
the Properties Window.
Assign report to the viewer programatically
In the Page_Load event handler you create a report instance. If the Report DataSource property changes
or hasn't been assigned in the designer, assign the data source after instantiating the report object.
Finally assign the report object to the ReportViewer Report property.
CopyC#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Report1 report1 = new Report1();
ReportViewer1.Report = report1;
}
}
CopyVB.NET
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
Dim report1 As New Report1()
ReportViewer1.Report = report1
End If
End Sub
See Also