在自定义 SharePoint WebPart 中使用 Microsoft.Reporting.WebForms.ReportViewer

发布于 2024-08-30 07:01:06 字数 1710 浏览 1 评论 0原文

我有一个要求,我必须显示一些数据(来自自定义数据库)并让用户将其导出到 Excel 文件。

我决定使用 Microsoft.Reporting.WebForms.ReportViewer 中存在的 ReportViewer 控件。我将所需的程序集添加到项目引用中,并添加以下代码来测试它

protected override void CreateChildControls()
        {
            base.CreateChildControls();

            objRV = new Microsoft.Reporting.WebForms.ReportViewer();
            objRV.ID = "objRV";
            this.Controls.Add(objRV);
        }

第一个错误要求我在 web.config 中添加这一行,

我这样做了,下一个错误说

The type 'Microsoft.SharePoint.Portal.Analytics.UI.ReportViewerMessages, Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' does not implement IReportViewerMessages

Is it possible to use ReportViewer in my custom网络部分?我宁愿不绑定中继器并编写自己的导出到 Excel 代码。我想使用 Microsoft 已经构建的东西?关于我可以重用什么有什么想法吗?

编辑

我评论了以下行

<add key="ReportViewerMessages"...

,现在我的代码在添加数据源后看起来像这样,

protected override void CreateChildControls()
        {
            base.CreateChildControls();

            objRV = new Microsoft.Reporting.WebForms.ReportViewer();
            objRV.ID = "objRV";
            objRV.Visible = true;

            Microsoft.Reporting.WebForms.ReportDataSource datasource = new Microsoft.Reporting.WebForms.ReportDataSource("test", GroupM.Common.DB.GetAllClientCodes());
            objRV.LocalReport.DataSources.Clear();
            objRV.LocalReport.DataSources.Add(datasource);

            objRV.LocalReport.Refresh();

            this.Controls.Add(objRV);
        }

但现在我在页面上看不到任何数据。我确实检查了我的数据库调用,它确实返回了一个包含 15 行的数据表。有什么想法为什么我在页面上看不到任何内容吗?

I have a requirement where I have to display some data (from a custom db) and let the user export it to an excel file.

I decided to use the ReportViewer control present in Microsoft.Reporting.WebForms.ReportViewer. I added the required assembly to the project references and I add the following code to test it out

protected override void CreateChildControls()
        {
            base.CreateChildControls();

            objRV = new Microsoft.Reporting.WebForms.ReportViewer();
            objRV.ID = "objRV";
            this.Controls.Add(objRV);
        }

The first error asked me to add this line in the web.config

which I did and the next error says

The type 'Microsoft.SharePoint.Portal.Analytics.UI.ReportViewerMessages, Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' does not implement IReportViewerMessages

Is it possible to use ReportViewer in my custom Web Part? I rather not bind a repeater and write my own export to excel code. I want to use something which is already built by Microsoft? Any ideas on what I can reuse?

Edit

I commented the following line

<add key="ReportViewerMessages"...

and now my code looks like this after I added a data source to it

protected override void CreateChildControls()
        {
            base.CreateChildControls();

            objRV = new Microsoft.Reporting.WebForms.ReportViewer();
            objRV.ID = "objRV";
            objRV.Visible = true;

            Microsoft.Reporting.WebForms.ReportDataSource datasource = new Microsoft.Reporting.WebForms.ReportDataSource("test", GroupM.Common.DB.GetAllClientCodes());
            objRV.LocalReport.DataSources.Clear();
            objRV.LocalReport.DataSources.Add(datasource);

            objRV.LocalReport.Refresh();

            this.Controls.Add(objRV);
        }

but now I do not see any data on the page. I did check my db call and it does return a data table with 15 rows. Any ideas why I don't see anything on the page?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绾颜 2024-09-06 07:01:06

您是否在 SharePoint Web 应用程序下运行报表服务器?将 添加到报告站点的 web.config,或删除 <您的共享点 web.config 中的 /code> 应该可以清除它。不过,不确定这会如何影响 ootb reportviewer Web 部件(测试、测试、测试)...

Are you running a report server under a SharePoint web app? Adding <remove key="ReportViewerMessages" /> to your web.config of the reporting site, or removing the <add key="ReportViewerMessages"... /> from your sharepoint web.config should clear it up. Not sure how that would impact the ootb reportviewer web part, though (test, test, test)...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文