2

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.

1

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.FilteredDataSourcePropertyFormat,
            _grid.FilterFieldValue.Replace("'", "''"),
            _grid.FilterFieldName);
    }
    base.OnPreRender(e);
}

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

0

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.