
RdlcRptGen Class 10
Generate local reports and charts at run-time, using the Microsoft ReportViewer Control, user specified options, and the RdlcRptGen Class.
How The RdlcRptGen Class Works
Following is an example of the easiest way to produce a report or chart from an
existing DataTable using Visual Studio. Also a free, full source code, example of a possible
end-user selection web page, that utilizes the RdlcRptGenClass to generate the
report or chart based on the end-user selections, is available
here
or by clicking on the Down Load Trial Version menu item above.
Prior to running the code below, the following action need to be taken.
1.Copy the RdlcGenClass.dll file to the bin directory of your project.
2.Add a reference to the RdlcGen Class in your project.
3.Create a DataTable named TestDataTable with the data that you wish to report. This can be done in several ways, please consult your help resources for additional information on how to create a DataTable.
4.Add a Microsoft ReportViewer to your form. You may need to add a reference to it in your project. Accept the default name of ReportViewer1 for the control.
Note: This control is avalible in Ver 2.5 for use with ReportViewer 9, or Ver 10
for use with ReportViewer 10.
Sample Code.
//Initialize the Class and pass the TestDataTable and the reportViewer1 object.
//That's all that is required. The data from the TestDataTable will be reported in the reportViewer1.
var NewRdlcGenClass = new RdlcRptGen.RdlcGenClass(TestDataTable, reportViewer1 );
Other options are available to further refine the report or chart.
//Initialize the Class and only pass the TestDataTable object.
var NewRdlcGenClass = new RdlcRptGen.RdlcGenClass(TestDataTable );
//Then optionally select a grouping field. The report will then be grouped by
this field.
NewRdlcGenClass.GroupByField = "GrpFieldName";
//Optionally select report and group total column. These columns will be
totaled on the generated report.
NewRdlcGenClass.AddReportTotalFields("RptTotalField");
NewRdlcGenClass.AddGroupTotalFields( "GrpTotalField");
//Optionally select the columns to be included in the report.
//The second and third parameter, the column width, and the ColumnHeader need not be provided,
//The default values will be used.
NewRdlcGenClass.AddReportColumns("FieldName1", “2in”, "Field1ColumnHeader");
NewRdlcGenClass.AddReportColumns("FieldName2", “3in”, "Field2ColumnHeader");
//Optionally include a report header.
NewRdlcGenClass.AddReportHeader("This is a report header");
//Optionally generate the report definition file (RDLC). This file may optionally be
saved for future use
NewRdlcGenClass.GenerateRdl();
//Optionally access the XML Document and make any custom changes that are required.
XmlElement report = (XmlElement)NewRdlcGenClass.doc.FirstChild.NextSibling;
AddElement(report, "Width", "8.00in");
//Optionally add a Drill Down field to the report. When the drill down link is click
it will call the Drilldown method
//of the report viewer.
NewRdlcGenClass.AddDrillDwnInfo(DrillDownFieldName,
FieldValueToPassToDrillDownMethod) ;
….............................................................................
…............................................................................
//Then show the report.
NewRdlcGenClass.ShowReport(ReportViewer1);
To show a Chart rather than a record based report
//Initialize the Class and only pass the TestDataTable object. This is
the same as when showing a records based report.
var NewRdlcGenClass = new RdlcRptGen.RdlcGenClass(TestDataTable );
//Optionally add at least one Data Point. Optionally include the calculation method,
IE "Count, CountDistinct, Sum". If Chart
//type is not provided, the default of "Count" or "Sum" will be used
based on the field data type. Unlimited number
//of Data Points can be added. If no Data Points are provided
then all fields in the DataTable will be used.
// Note: In Version 2.5 at least one Data Point must be provided.
NewRdlcGenClass.AddChartDataPoint("DataPointFieldName", "Sum");
//Optionally add a Chart Title.
NewRdlcGenClass.AddChartTitle("This is the title of this Chart");
//Optionally add ChartType (Pie,Line,Column,Bar) and Chart Grouping field
name. If the information is not
//provided the defaults, of Chart Type="Column" and no Chart Grouping, will be used.
NewRdlcGenClass.AddChartTypeAndGrouping("Column", "GroupByField");
//Optionally add Data Point labels, X Axis and Y Axis labels. The default
is no labels.
NewRdlcGenClass.ChartLabels(true, "X Axis label" , "Y Axis label );
//Then show Chart report.
NewRdlcGenClass.ShowChart(ReportViewer1);