SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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