0

I have an SPGridView, SPGridViewPager and an Object data source that are all pre-defined in the ascx.

The grid are just populated by the code behind with the object data source.

The grid view is inside an update panel

My issue is when i filter the view, and go to the next page, the filter is persisted but I cannot clear the Filter anymore the 'Clear filter' for the column in the view is disabled.

I also set the FilterExpression on Pre Render.

    protected override void OnPreRender(EventArgs e)
    {
         base.OnPreRender(e);
        if (!string.IsNullOrEmpty(this.FilterExpression))
        {
            this.MyDataSource.FilterExpression =  this.FilterExpression;
            this.ViewState["FilterExpression"] = this.FilterExpression;
        }
    }
0

In case someone stumbles upon the same issue, i have solved it by setting the FilterFieldName attribute on my controls Pre Render event:

FilterFieldName property of the gridview cannot be set directly you have to set it by using "Attribute".

    if (!string.IsNullOrEmpty(this.FilterExpression))
        {
            string[] columns = this.FilterExpression.Split(new[] { "like" }, StringSplitOptions.RemoveEmptyEntries);
            if (columns != null)
            {
                string[] columnFieldName = columns[0].Split(new[] { "(" }, StringSplitOptions.RemoveEmptyEntries);
                string filteringColumn = columnFieldName[0].ToString();
                this.MyGridView.Attributes["FilterFieldName"] = filteringColumn.Trim();

            }
        }

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.