ReportViewer 2010 未从代码加载数据源
我在 ASP.NET 中创建了一个带有简单 RDLC 报告的项目,当我在设计时使用 SqlDataSource
绑定报告的 DataSource
时,一切工作正常。但是,如果我删除绑定并尝试从代码中设置DataSource
,那么报告似乎永远不会停止加载。
我过去曾在 WinForms 应用程序上使用过此操作,没有遇到任何问题,但这是我第一次尝试在 ASP.NET 中执行此操作,但没有成功。
以下是我用来在 Page_Load
事件中设置 DataSource
的代码。正如我所说,使用相同的 SqlDataSource
,如果它绑定在 .aspx
页面中,它就可以工作。
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()
即使我直接在报表查看器控件中设置报表并将代码缩减为...
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("DataSet1", SqlDataSource1))
ReportViewer1.LocalReport.Refresh()
...它仍然会执行相同的操作。
此外,在 Visual Studio 中加载报告时,您可以看到不断生成大量脚本块(列表框不断增长):
当这个过程发生时,加载旋转器只是旋转到一半,重新启动并重复。但页面没有重新加载。
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,像往常一样,在您发布问题后不久,您就会找到解决方案。
解决方案是确保仅当页面不是回发时才执行
DataSource
的设置。简而言之,将代码块包装在:我猜这是因为reportviewer 的AJAX 性质?如果有人能解释为什么会出现这种情况,我很想听听。
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: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.