根据brian brinley提供的链接,我想出了这个稍微通用的解决方案:
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);
}
}
}