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

how to implement dynamic embedded expressions

1 Answer 123 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kenneth
Top achievements
Rank 2
Iron
Kenneth asked on 28 Apr 2014, 04:01 PM
I am creating a report that is basically a business letter.  I load the body of the letter from a database.  It is text with embedded variables, like the client’s name and address.  I currently have this working where I replace the variables in the body with the corresponding data in a class, but I thought it would be nice to let the report generator do that for me.

So I would like to have the body use the same expressions as the reports do.  So a body might look like this: “This is the body of the letter Mr. {Fields.Lastname}.”  Of course, I don’t know what the body actually is until the user runs the report.

So I would need to access the textbox that the body would appear in, set it’s value to the body text, programmatically setup a datasource with the data to be used to evaluate the expressions, the somehow data bind it so the expressions in the body are evaluated against the new data source.

Is this possible and if so are there some examples or documentation that would help?

1 Answer, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 01 May 2014, 12:19 PM
Hello Kenneth,

The preferred approach is to set the TextBox to get the current user from a report parameter. Then retrieve the current user in your application and assign it to the report parameter. For more information, please check the Report Parameters help articles.

You can also programmatically change the TextBox.Value property just before the report is displayed in the report viewer. This can be achieved by setting the new TextBox.Value (e.g. "This is the body of the letter Mr. {Fields.Lastname}.") in your application code.

For example, if you are using the WebForms viewer the code will look like this:
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        var report = new MyReport();
        var textBox = report.Items.Find("textBoxName", true)[0] as Telerik.Reporting.TextBox;
        textBox.Value = "set new text box value";
 
        var instanceReportSource = new Telerik.Reporting.InstanceReportSource();
        instanceReportSource.ReportDocument = report;
        this.ReportViewer1.ReportSource = instanceReportSource;
    }
}

If you need further help, please send us additional information about your scenario such as screenshots, report definition or an isolated sample project which you can zip and attach in a separate support ticket.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
Kenneth
Top achievements
Rank 2
Iron
Answers by
Nasko
Telerik team
Share this question
or