get the access to a class implementing a web - part

问题 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.aspx

    Thanks,


    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:48
     
     
    thanks, 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