This is a migrated thread and some comments may be shown as answers.

Tip: Poulating Fields with Custom Objects

1 Answer 143 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 11 Oct 2007, 11:53 PM
I recently ran in to a problem using the reporting tools where I had a custom object with no blank constructor. In order to make the reports dynamic and change the report based on some sort of id supplied I came up with the following solution.

Explanation of Process:

Object Car is pulled from the database
Fields of object car are placed in to fields of report

    public partial class CarReport : Report { 
        public CarReport() { 
        } 
 
        public CarReport(int id){ 
            Car c = GetFromDB.GetCar(23); 
            txtName.Value = c.Name; 
            txtType.Value = c.Type; 
        } 
    } 
 
 
    class GetFromDB { 
        public Car GetCar(int id) { 
            //Query Datbase and parse info 
 
            return new Car("FastCar", "Porsche"); 
        } 
 
    } 
 
    class Car { 
        private string strName; 
        private string strType; 
 
        public Car(string Name, string Type) { 
            strName = Name; 
            strType = Type; 
        } 
 
        public string Name { get { return strName; } } 
        public string Type { get { return strType; } } 
    } 


So by doing the following and creating an instance of the Report, binding it to the report viewer, you can have any object bound to any field on the report. I hope this helps.

1 Answer, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 12 Oct 2007, 10:53 AM
Hi John,

Thank you for participating in the Telerik Reporting Forum Discussions. Keep up the good work.

Your account has been updated with 500 Telerik Points.

Sincerely yours,
Ross
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
General Discussions
Asked by
John
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question
or