Reputation: 5209
I have created a project with a simple RDLC report in ASP.NET which when I bind the DataSource
of the report at design time using a SqlDataSource
everything works just fine. But if I remove the binding and try to set the DataSource
from code then the report seems to never stop loading.
I've worked with this on WinForms apps in the past and had no problems, but this is the first time I've tried to do it in ASP.NET, with no luck.
Here's the code I'm using to set the DataSource
in the Page_Load
event. As I said using the same SqlDataSource
that works if it's bound in the .aspx
page.
ReportViewer1.Reset()
ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc")
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("DataSet1", SqlDataSource1))
ReportViewer1.LocalReport.Refresh()
Even if I set the report directly in the reportviewer control and chop the code down to just...
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("DataSet1", SqlDataSource1))
ReportViewer1.LocalReport.Refresh()
...it still does the same.
Also, in Visual Studio while the report is loading you can see that a huge amount of script blocks are constantly being generated (the listbox keeps growing):
While this is going on the loading spinner is just going round halfway, restarting and repeating. The page isn't reloading though.
Any thoughts?
Upvotes: 4
Views: 4223
Reputation: 5209
OK, as usual not long after you post a question, you find a solution.
The solution to this was to make sure the setting of the DataSource
is only performed when the page is not a postback. SO in short wrap the code block in:
If Not Page.IsPostBack Then
<set datasource here>
End If
I guess this is because of the AJAX nature of the reportviewer? If anyone could shed any light on why this is the case I'd be interested to hear it.
Upvotes: 7