I have experienced a funny behavior by having two SPGridviews along with ObjectDataSource on the same page. Both the SPGirdViews are enabled with sorting, filtering and pagination. Filtering and Pagination worked perfectly without any issues. If it comes to sorting point of view, whenever you try to sort the lower SPGridView it gets applied to upper SPGridView.
The Hack for this issue:
protected override void OnPreRender(EventArgs e)
{
if (SPGridView1.HeaderRow != null)
{
foreach (WebControl control in this.SPGridView1.HeaderRow.Controls)
{
UpdateTemplateClientID(control, SPGridView1.ClientID);
}
}
if (SPGridView2.HeaderRow != null)
{
foreach (WebControl control in this.SPGridView2.HeaderRow.Controls)
{
UpdateTemplateClientID(control, SPGridView2.ClientID);
}
}
base.OnPreRender(e);
}
private void UpdateTemplateClientID(Control control, string clientID)
{
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%", clientID + "_SPGridViewFilterMenuTemplate");
}
else if (control.HasControls())
{
foreach (WebControl c in control.Controls)
{
UpdateTemplateClientID(c, clientID);
}
}
}