Using Microsoft.Reporting.WebForms.ReportViewer in a custom SharePoint WebPart
        Posted  
        
            by iHeartDucks
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by iHeartDucks
        
        
        
        Published on 2010-04-27T15:42:14Z
        Indexed on 
            2010/04/27
            18:03 UTC
        
        
        Read the original article
        Hit count: 1181
        
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?
© Stack Overflow or respective owner