SPGridview Filter is being cleared on paging events
-
10-10-2020 - |
Frage
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;
}
}
Lösung
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();
}
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange