For winview reportviewer: include the following code
public class Dog { int legs; public int Legs { get { return legs; } set { legs = value; } } string name; public string Name { get { return name; } set { name = value; } } string breed; public string Breed { get { return breed; } set { breed = value; } } } public class DogBll { List<Dog> myDog; public DogBll() { myDog = new List<Dog>(); myDog.Add(new Dog() { Legs = 10, Name = "mimi", Breed = "german" }); myDog.Add(new Dog() { Legs = 4, Name = "momo", Breed = "english" }); } public List<Dog> GetDogs() { return myDog; } }
create your own solution, add a reportviewer control to your form, in smartview from reportviewer, create a new report and select an object data source, expand your class and check the Dog class as an object data source. select the ReportViewer control again and select the newly created report, automatically create the DogBindingSource object. In your form class, add the following code to the top of the class. You can use the first line after the open partial class Form1: Form {statement, but before the constructor
private DogBll _dogBll = new DogBll();
In formload () add:
this.DogBindingSource.DataSource = _dogBll.GetDogs();
For webform reportviewer: you must provide a function that returns a Dog list, in this class it must contain a default constructor.
namespace MyNS { public class Dog { public int Legs { get; set; } public string Name { get; set; } public string Breed { get; set; } } public class DogBll { public DogBll() { } public List<Dog> GetDogs(List<Dog> myDog)
add a control for the report view wizard, select the data source as the new function you just created, GetDogs (), define your report based on 3 public properties in your Dog class. Add an object data source to your form, specify a report to use the object data source. Finally, set the GetDogs () parameter in the object's data source.
source share