Problem Sorting With Multiple SPGridViews
I am using an SPGridView control with an ObjectDataSource control in a SharePoint 2010 solution. The SPGridview allows me to sort and page through a list items OK, but I have noticed a problem when two SPGridView controls are placed on the same page. When I sort the lower SPGridView control by clicking on a column's header link, the sort operation is successful. However when I click on the sort options availabl开发者_运维技巧e through the ECB menu on the lower SPGridView's column header, the sort is applied to the upper SPGridView control instead.
Can anyone offer a fix or guidance on how to resolve this?
Thanks, MagicAndi.
Here is a thread on MSDN explaining the bug and a resolution.
http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/af6167a3-21f2-4bb2-94a9-5c22e1aad34d
Here is another blog post describing it as well - http://sharethefrustration.blogspot.com/2010/02/spgridview-webpart-with-multiple-filter.html
Based on the links provided by brian brinley, I came up with this slightly more generic solution:
protected override void OnPreRender(EventArgs e)
{
if (this.HeaderRow != null)
{
foreach (WebControl control in this.HeaderRow.Controls)
{
UpdateTemplateClientID(control);
}
}
base.OnPreRender(e);
}
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);
}
}
}
精彩评论