How do I bind to a field with special characters?

3 posts, 1 answers
  1. John
    John avatar
    7 posts
    Member since:
    Aug 2015

    Posted 13 Aug 2015 Link to this post

    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. Answer
    Nasko avatar
    1090 posts

    Posted 14 Aug 2015 Link to this post

    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]

    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
  3. John
    John avatar
    7 posts
    Member since:
    Aug 2015

    Posted 14 Aug 2015 Link to this post

    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.

Back to Top