how to bind a field in the report with an object of a class

Posted by: snehajose1990 on 22 September 2019, 10:53 pm EST

  • Posted 22 September 2019, 10:53 pm EST


    I have an old report where the datafield property of the fields is assigned to property of a class. e.g. in the report one of the fields data field property is : =myclass.itemID.
    Programmatically how can we declare the object of the class so that the report will identify the object directly and assign its property value. I tried to use AddNamedItem method but that doesn't work. How can we fetch the values in such scenario.

    Your help will be highly appreciated.

  • Replied 22 September 2019, 11:16 pm EST

    Hello Sneha,

    Please write the following code in script of the report to access the variable of the class instead of in "DataField" property;
    public void Detail_Format()
    this.TextBox1.Text = myclass.itemId;

    Pelase refer to the attached image for more clarification.

    Hope it helps.

  • Replied 22 September 2019, 11:47 pm EST

    Hi Mohit,

    Thanks for your reply.
    Actually I have around 140 reports existing in our application which of version AR2 and we are migrating to AR13 . All the reports already have datafield property which is set to class property. we do not want to make any changes in these reports but want to handle it in the code. Is there a way this can be achieved.
  • Replied 23 September 2019, 4:43 pm EST

    Hi Mohit,

    Any update??

  • Marked as Answer

    Replied 23 September 2019, 5:37 pm EST


    You can use the following line on code to set the value of the TextBox if you don't want to edit the report.

    public Form1()
    GrapeCity.ActiveReports.SectionReport sectionReport = new GrapeCity.ActiveReports.SectionReport();
    System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(@"..\..\SectionReport1.rpx");


    sectionReport.Sections["Detail"].Format += Form1_Format;

    private void Form1_Format(object sender, EventArgs e)
    GrapeCity.ActiveReports.SectionReportModel.Detail detail = (GrapeCity.ActiveReports.SectionReportModel.Detail)sender;

    (detail.Controls["TextBox1"] as GrapeCity.ActiveReports.SectionReportModel.TextBox).Text = test.itemId;

    Hope it helps.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels