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

Supressing binding errors

1 Answer 79 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Emil Alexiev
Top achievements
Rank 1
Emil Alexiev asked on 13 Sep 2011, 11:55 PM
I have a report which binds to a Dataset.  Dataset loads an xml file which sometimes doesn't contain all elements (if user didnt specify any data for those elements).  If an element such as 'Name' is missing I will receive "An error has occurred while processing TextBox 'Name': The expression contains object 'Name' that is not defined in the current context".  Instead I just want the report to leave the textbox blank if the binding fails.  Is it possible to somehow supress binding errors if the biniding element doesn't exist?
Thanks, Emil.

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 16 Sep 2011, 01:37 PM
Hello Emil Alexiev,

In order to avoid the expression's exception our suggestion is to utilize the following user function:

public static string GetValue(Processing.ReportItem reportItem, string field)
{
    try
    {
        return reportItem.DataObject[field].ToString();
    }
    catch
    {
         return "";
    }
}
Once you add the GetValue user function, build the project and use the following expression for the TextBox.Value:
= GetValue(ReportItem,"Name")

All the best,
Peter
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
General Discussions
Asked by
Emil Alexiev
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or