This is a migrated thread and some comments may be shown as answers.
How do I bind to a field with special characters?
2 Answers 38 Views
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 13 Aug 2015, 09:53 PM

I am trying to bind a TextBox to an a dynamically named column using expressions.

var textBoxHistorical = new TextBox
{
    Name = "myTextBox",
    Value = "= Fields.[" + ​dynamicColumnName+ "_​Average])",
    Size = new SizeU(Unit.Pixel(100), Unit.Pixel(20)),
    Location = new PointU(Unit.Pixel(0), Unit.Pixel(0))
};

The column name can have ugly characters like \/*[]:?|-+@#$$^&()_,.!3. When I try to bind to Fields.[\/*[]:?|-+@#$$^&()_,.!3_​Average], I get an error like

     Cannot interpret token '\' at position 13.

I tried escaping the slash with another slash, and got the same error. How do I escape characters in an expression? Which characters do I need to escape? I figure I need to escape the closing bracket also, but trial by error is probably not the best way to solve the problem.

2 Answers, 1 is accepted

Sort by
0
Accepted
Nasko
Telerik team
answered on 14 Aug 2015, 11:11 AM
Hello John,

The issue is that the field name itself contains square brackets, which are used by default to enclose the field name. You need to escape those square brackets with a backslash as described in the Global Objects | Fields help article.
For example, the following expression does not produce an error:

= Fields.[\/*\[\]:?|-+@#$$^&()_,.!3_​Average]

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
John
Top achievements
Rank 1
answered on 14 Aug 2015, 03:53 PM

Thank you, Nasko. I created a brand new blank report to test your answer, and it worked. I was able to bind a table to a CsvDataSource that had a column named  \/*[]:?|-+@#$$^&()_,.!3.

Asked by
John
Top achievements
Rank 1
Answers by
Nasko
Telerik team
John
Top achievements
Rank 1
Share this question
or