0
votes

I have a Telerik RadGrid. I am using auto-generated columns, reading the column definitions from database. One of my stored column names in the database has an apostrophe inside its textual content. My data-source loads without a problem, but when I try to filter by the column (with apostrophe), I get the client-side error:

Uncaught SyntaxError: Unexpected identifier

My question is: How can I tell my Telerik RadGrid to escape the apostrophe, so the client-side Telerik functionality will be usable even if the UniqueName of the column contains an apostrophe?

Thank you in advance for any help,

Best regards,

Lajos Árpád.

2
Having an apostrophe in your database column name is a really bad idea. The best solution would be to rename your column. - Francis P
Nope, my column names in the database don't have apostrophe inside them, however, my AutoGenerated columns at the RadGrid are defined based on user-defined settings. The RadGrid's column definitions are stored in database rows in a table. The table has a column for "ColumnName" and each row in the table has a ColumnName value. Essentially a row of this table has an apostrophe in its ColumnName field value. These are user-defined settings and I would like to allow them to put apostrophes inside their column names, SQL injection and other problems regarding ' in a varchar is handled. - Lajos Arpad
My question is not about how to store apostrophe in varchar values and not about should I store apostrophe in a varchar. I have to support people to name their columns as they want. I've made a workaround to bypass Telerik's bug of cracking when trying to filter by a column which has an apostrophe in its UniqueName, but I hope there is a better solution than replacing the apostrophe in the UniqueName to whatever else "manually" and to parse the HeaderText because of the previously mentioned hack. - Lajos Arpad
Also, you didn't understand the situation, maybe it's my fault. I didn't say that a "database column" has an apostrophe in its name, I have only said that I read my column definitions from the database. These definitions are not schema definitions, they are values instead. So no, I don't rename my columns and I don't change the values stored in the database. - Lajos Arpad
Have you tried storing HTML code ' instead of '? - Francis P

2 Answers

0
votes

I have worked out an answer, if anybody has a better alternative, I will happily accept his/her answer.

Before I get the data source I Replace the apostrophes in the Keys of the columns with something and in the ColumnCreated event of the RadGrid I replace that something in the HeaderTexts of the columns with apostrophe. This way the user will see the apostrophe in the Header Text and in the logical background something else is used in the place of the apostrophes to make sure the Telerik bug of being unable to handle column identifiers containins apostrophes is worked around.