views:

714

answers:

1

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?

A: 

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)...

vinny
Thanks, I tried what you said and it worked. However, I am not using the WebPart I am simple using the class from Microsoft.Reporting.WebForms. I did not yet explore the outcome of the action.
iHeartDucks
Thanks, I will check it out
iHeartDucks

related questions