2014-01-27 63 views

回答

3

要添加任何東西,除了一個複選框(布爾)或文本框(串),你需要做更多的工作,並創建一個自定義ToolPart對象。有一個從this question一個良好的基礎,這裏顯示的是如何做到這一點的基礎知識一些示例代碼:

Screen shot of simple tool part

using System; 
using System.ComponentModel; 
using System.Web; 

namespace SharePointProject1.SimpleWebPart 
{ 
    [ToolboxItemAttribute(false)] 
    public class SimpleWebPart : Microsoft.SharePoint.WebPartPages.WebPart 
    { 
     protected override void CreateChildControls() 
     { 
      //Do the actual work of the web part here 
     } 

     public override Microsoft.SharePoint.WebPartPages.ToolPart[] GetToolParts() 
     { 
      //First add base tool parts and then our simple one with a hyperlink 
      Microsoft.SharePoint.WebPartPages.ToolPart[] toolPartArray = new Microsoft.SharePoint.WebPartPages.ToolPart[3]; 
      toolPartArray[0] = new Microsoft.SharePoint.WebPartPages.CustomPropertyToolPart(); 
      toolPartArray[1] = new Microsoft.SharePoint.WebPartPages.WebPartToolPart(); 
      toolPartArray[2] = new mySimpleToolPart(); 

      return toolPartArray; 
     } 
    } 

    //Implements a custom ToolPart that simply displays a link 
    public class mySimpleToolPart : Microsoft.SharePoint.WebPartPages.ToolPart 
    { 
     public mySimpleToolPart() 
     { 
      //You could pass this as a parameter to the class 
      this.Title = "This is the title"; 
     } 

     protected override void CreateChildControls() 
     { 
      System.Web.UI.WebControls.HyperLink simpleLink = new System.Web.UI.WebControls.HyperLink(); 
      simpleLink.Text = "Click on this Link"; 
      simpleLink.NavigateUrl = "http://www.google.com"; 
      Controls.Add(simpleLink); 
      //Add some white space 
      Controls.Add(new System.Web.UI.HtmlControls.HtmlGenericControl("p")); 
     } 
    } 
} 
相關問題