In SpGridview single quote is breaking the filter expression as we are having filter format as "{1} like '{0}'",any idea how we can handle this situation.


You will need to override the OnPreRender method to escape the single quotes:

protected override void OnPreRender(EventArgs e)
    if (!string.IsNullOrEmpty(_gridDS.FilterExpression))
        _gridDS.FilterExpression = string.Format(
            _grid.FilterFieldValue.Replace("'", "''"),

You can check out the full blog post here: SharePoint’s SPGridView, filtering, and apostrophes (full disclosure, this is my blog).

You can also check out a similar question on StackOverflow: SPGridView, data and correct method of ensuring data is safe


I suggest using ‘=’ instead of ‘LIKE’ as filtering columns with number values (SPField of type Integer or Number) throws exception. ‘=’ in SQL can be used for text as well as for number comparisons. Give it a try.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.