If filtering is enabled on the controls, when the user clears the filter on the second SPGridView on the screen, the filter on the first SPGridView is cleared instead.
After some searching, I found a nice solution to this problem here.
I copied the suggested solution into a class that inherits from SPGridView and used that in my WebParts to resolve the problem:
public class MySPGridView : SPGridView { // Override the OnPreRender to databind and then fix each headerrow control protected override void OnPreRender(EventArgs e) { DataBind(); if (this.HeaderRow != null) { foreach (WebControl control in this.HeaderRow.Controls) { UpdateTemplateClientID(control); } } base.OnPreRender(e); } // Fix the ClientOnClickPreMenuOpen property of a menu control private void UpdateTemplateClientID(Control control) { if (control is Microsoft.SharePoint.WebControls.Menu) { Microsoft.SharePoint.WebControls.Menu menuControl = control as Microsoft.SharePoint.WebControls.Menu; string jsFunctionCall = menuControl.ClientOnClickPreMenuOpen; menuControl.ClientOnClickPreMenuOpen = jsFunctionCall.Replace("%TEMPLATECLIENTID%", this.ClientID + "_SPGridViewFilterMenuTemplate"); } else if (control.HasControls()) { foreach (WebControl c in control.Controls) UpdateTemplateClientID(c); } } }
No comments:
Post a Comment