您的位置:首页 > 运维架构

sharepoint中自定义webpart属性面板(Web Part Properties(ToolPart))

2009-05-13 13:49 483 查看
在sharepoint中webpart是少不了的,要是定制自己的webpart,webpart属性也少不了,但是微软提供给我们的方式有限,见:
http://msdn.microsoft.com/en-us/library/dd584174.aspx
但是这个方式还是比较好的http://msdn.microsoft.com/en-us/library/dd584178(office.11).aspx

这也有一篇http://www.zimmergren.net/archive/2008/11/29/how-to-custom-web-part-properties-toolpart.aspx

webpart代码

Code
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;

namespace Zimmergren.CustomToolPart
{
public class CustomToolPart : Microsoft.SharePoint.WebPartPages.ToolPart
{
DropDownList ddl;
Panel toolPartPanel;
TextBox tb;

protected override void CreateChildControls()
{
toolPartPanel = new Panel();
ddl = new DropDownList();
ddl.ID = "ddl";

// Simply getting the lists of the current web, and displaying them in the dropdown-list.
SPListCollection lists = SPContext.Current.Web.Lists;
foreach (SPList list in lists)
ddl.Items.Add(list.Title);

tb = new TextBox();
tb.ID = "tb";

toolPartPanel.Controls.Add(ddl);
toolPartPanel.Controls.Add(tb);

Controls.Add(toolPartPanel);
base.CreateChildControls();
}

public override void ApplyChanges()
{
WebPart111 wp = (WebPart111)this.ParentToolPane.SelectedWebPart;
wp.Property1 = ddl.SelectedValue;
wp.Property2 = tb.Text;
}

}
}

简单的结果



稍微复杂点的



属性面板选list 的参见:http://www.tonstegeman.com/Blog/Lists/Posts/Post.aspx?List=70640fe5-28d9-464f-b1c9-91e07c8f7e47&ID=72
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: