get the access to a class implementing a web - part
-
2012年6月28日 6:45
thisWeb = SPContext.Current.Site.RootWeb; Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager webPartManager = thisWeb.GetLimitedWebPartManager("page.aspx", PersonalizationScope.Shared); WebPart webpart1=null; foreach (WebPart p in webPartManager.WebParts)
{ if (p.DisplayTitle.Equals("my panel"))
{
webpart1 = p; break; } }
There is an instance a pps web-part (webpart1) type Microsoft.PerformancePoint.Scorecards.WebControls.ScorecardWebPart.
I need to change a webpart1.
How to get the access to a class implementing a web - part?
MS
全部回复
-
2012年7月3日 6:41版主
Hi Che097,
To access a web part with specific type, you can try the following code snippet:
if (webpart.GetType().Name.ToString().Equals("XsltListViewWebPart")){
ListViewWebPart listviewwebpart = (ListViewWebPart)webpart;
}
Then you can do your updates to the web part.
More information:
http://panvega.wordpress.com/2009/09/08/acessing-webparts-in-a-page-using-the-sp-object-model/
http://spblog.net/post/2011/04/26/Changing-default-view-for-ListViewWebPart-programmatically.aspxThanks,
Qiao Wei
TechNet Community Support
-
2012年7月3日 7:29
Hi ,
try like this,
thisWeb = SPContext.Current.Site.RootWeb; Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager webPartManager = thisWeb.GetLimitedWebPartManager("page.aspx", PersonalizationScope.Shared); Microsoft.PerformancePoint.Scorecards.webcontrols.ScorecardWebpart webpart1=null; foreach (WebPart p in webPartManager.WebParts) { if (p.DisplayTitle.Equals("my panel")) { webpart1 = p as Microsoft.PerformancePoint.Scorecards.webcontrols.ScorecardWebpart; break; } }Thanks,
Sudan
-
2012年7月3日 9:42
Hi,
You can use an expression as shown below:
if(p is webpart1) { //this is your webpart1 }
Thanks,
Sohel Rana
http://ranaictiu-technicalblog.blogspot.com -
2012年7月4日 8:48thanks, but I need to change a ScorecardWebPart. How to work with object perforamncePoint ScorecardWebPart? How to change data in a ScorecardWebPart?
MS
-
2012年7月5日 10:29版主
Hi,
there seems no documentation for the scorecard class, you may not be able to update data in the object through code.
Thanks,
Qiao Wei
TechNet Community Support
- 已编辑 Qiao WeiMicrosoft Contingent Staff, Moderator 2012年7月6日 3:07

