In the below example I have a number of public classes that are defined in a namespace. These are going to be instantiated, bound to ReportDataSets and handed off to my ReportViewer control to generate a report from my report definition files. When I try to access these classes in the Report Data window of the report designer for my .RDLC files, however, it only shows a few of the classes I've defined. What's going on, where are all the rest?
namespace Namespace1
{
public class Class1
{
public string String1 { get; set; }
}
public class Class2
{
public string String1 { get; set; }
}
}
Note: If you try to add the Class1 definition to the report page that requires Class2's data and then bind Class2 to the ReportDataSet before the report is generated, an exception will be thrown.
Click the dataset node in Solution Explorer to bring the DataSet Designer into focus. Click the Data Sources tab in the left margin of Visual Studio, or type data sources in the search box.
In Design view, on the View menu, select Report Data, or use CTRL+ALT+D.
In Solution Explorer (on the right of the Microsoft Visual Studio window), right-click Data Source Views, and then click New Data Source View. On the Welcome to the Data Source View Wizard page, click Next. The Select a Data Source page appears.
Go to Design view, Select Smart tag. Click Choose Report Dropdown, Select RDLC report (StudentReport). Click Choose Data Source and select <New data Source>. Select Object and Give DataSource Name.
When there are a number of classes with the same schema (all properties and their datatypes are the same), only the one that's first alphabetically will show up. But both will show up in the below example, because they do not have the same name for all properties (in this case, the one string).
namespace Namespace1
{
public class Class1
{
public string String1 { get; set; }
}
public class Class2
{
public string String2 { get; set; }
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With