Hi,
I am using an SPGridView to present some data, and have enabled the filtering ability which works very well. Until you choose a particular item in the data to filter on...
The data item in question has an apostrophe in the string( e.g. "this is richards' string"), which causes the post-filter-application page load to die with the error:
Syntax error: Missing operand after 's' operator.
Obviously the data is not automatically made safe...
The data is in a datatable, and the SPGridView is fed using an objectdatasource using the datatable.
Whats the best, or correct, method to ensure the data is safe to use?
EDIT:
After much gnashing, I have found a partial answer but the question still remains.
The partial answer is - you can make the data safe for the filter code, but you then cannot make it look correct in the filter dropdown gui.
Adding BoundField.HtmlEncode = true; to the SPGridView definition does nothing.
Using HttpUtility.HtmlEncode on the string does nothing.
Manually replacing all apostrophes in the data with ampersand #39; on insertion into the DataTable allows the filter to work fine, and the data displays fine in the SPGridView, but it displays with the html replacement string in the filter dropdown, and not the apostrophe character. This is the partial solution, and isn't really usable as it creates a horrible filter string which is visible to the end user.
I am still to find a complete solution to this problem, save for removing offending characters from the data altogether, which isn't really a solution.
Regards Richard