I wanna create a page report based on my custom class and my PageReport contains a table inside.
Say for example I have a Customer data class as follow
Class CustomerData
{
string name;
string id;
string address;
}
and I create a List<CustomerData>
CustomerList which contains all my customer data. I want to assign this data as the datasource for my Pagereport. I know In SectionReport we can do like this. But how to assign my list of information to PageReport. Could anybody help me
Ultimately I am expecting a output like something below
----------------------------------------------
|Name | ID | Address |
----------------------------------------------
|Name1 | ID1 | Address1 |
----------------------------------------------
|Name2 | ID2 | Address2 |
----------------------------------------------
|Name3 | ID3 | Address3 |
----------------------------------------------
ComponentIdInfo is one of the field
Do, something like this:
this._rptPath = new FileInfo(@"..\..\PageReport1.rdlx");
this._definition = new PageReport(this._rptPath);
this._definition.ConfigurationProvider = new GrapeCity.ActiveReports.Configuration.DefaultConfigurationProvider();
this._runtime = new PageDocument(this._definition);
this._runtime.LocateDataSource += this.runtime_LocateDataSource;
this.YourViewer.ReportViewer.LoadDocument(this._runtime);
And on your runtime_LocateDataSource
event, Add the following code:
private void runtime_LocateDataSource(object sender, LocateDataSourceEventArgs args)
{
object data = null;
string dataSetName = args.DataSetName;
string dataSourceName = args.DataSourceName;
if (StringsAreEqual("DataSource1", dataSourceName))
{
if (StringsAreEqual("DataSet1", dataSetName))
{
data = CustomerListDataTable;
}
}
args.Data = data;
}
private static bool StringsAreEqual(string str1, string str2)
{
return string.Compare(str1, str2, true, CultureInfo.InvariantCulture) == 0;
}
Please note that you have to create a DataSource
named DataSource1
and DataSet
named DataSet1
in your page report. And match the column names of DataSet1
to Customer's
class public properties
.
To get to the Add DataSource
, right click on just outside of your page report
(gray area) and select property
and look for DataSource
in the property
window.
How to Add DataSource/DataSet
Please note that if you cannot find Report Explorer
, go to Visual Studios
View
menu and go to Other Windows
.