Click here to Skip to main content
15,881,424 members
Articles / Web Development / ASP.NET

Using Custom Data Source to create RDLC Reports

Rate me:
Please Sign up or sign in to vote.
4.41/5 (11 votes)
7 Nov 2012CPOL5 min read 246K   6.4K   37  
Using custom list to create Report and report with Sub Report using RDLC and Report Viewer.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CpReportCustomData
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                rptViewer.LocalReport.SubreportProcessing += 
                    new Microsoft.Reporting.WebForms.SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
            }
        }

        void LocalReport_SubreportProcessing(
            object sender, 
            Microsoft.Reporting.WebForms.SubreportProcessingEventArgs e)
        {
            // get empID from the parameters
            int iEmpID = Convert.ToInt32(e.Parameters[0].Values[0]);

            // remove all previously attached Datasources, since we want to attach a
            // new one
            e.DataSources.Clear();

            // Retrieve employeeFamily list based on EmpID
            var employeeFamily = CpReportCustomData.Data.CustomDS.GetAllEmployeeFamily()
                                 .FindAll(element => element.ID == iEmpID);

            // add retrieved dataset or you can call it list to data source
            e.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource()
            {
                Name = "DSEmployeeFamily",
                Value = employeeFamily

            });

        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
He used to have biography here Smile | :) , but now he will hire someone (for free offcourse Big Grin | :-D ), Who writes his biography on his behalf Smile | :)

He is Great Fan of Mr. Johan Rosengren (his idol),Lim Bio Liong, Nishant S and DavidCrow and Believes that, he will EXCEL in his life by following there steps!!!

He started with Visual C++ then moved to C# then he become language agnostic, you give him task,tell him the language or platform, he we start immediately, if he knows the language otherwise he quickly learn it and start contributing productively

Last but not the least, For good 8 years he was Visual CPP MSMVP!

Comments and Discussions