SharePoint2010自定义工具栏
相信大家对自定义工具栏很有兴趣吧,在家里研究拉一下,把自己的代码给贴出来,给大家喜欢研究MOSS的哥们研究,研究 , 其实就是继承一个编辑类就OK拉,这个自定义工具栏,在实际的MOSS开发中,很有帮助的,很多地方需要他。。
//这个类是工具栏的编辑类,工具栏 ,主要靠他 using System; using System.Collections.Generic; using System.Text; using System.Web.UI.WebControls.WebParts; using Microsoft.SharePoint.WebControls;
namespace WebPartDemo { public class MyEditor : EditorPart { public MyEditor() { this.Title = "Custom Editor"; }
private PeopleEditor selPeople;
protected override void CreateChildControls() { selPeople = new PeopleEditor(); Controls.Add(selPeople); }
public override bool ApplyChanges() { EnsureChildControls(); (WebPartToEdit as WebPartDemo).DefaultTitle = selPeople.CommaSeparatedAccounts; return true; }
public override void SyncChanges() { EnsureChildControls(); selPeople.CommaSeparatedAccounts = (WebPartToEdit as WebPartDemo).DefaultTitle; } } }
下面就是在我们的实际的运用中,运用到他,代码测试过,可以直接运用。
using System; using System.Runtime.InteropServices; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Serialization; using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using Microsoft.SharePoint.WebPartPages; using System.Collections.Generic;
namespace WebPartDemo { [Guid("f7145e12-c25e-419f-90bd-ffe928ba084d")] public class WebPartDemo : System.Web.UI.WebControls.WebParts.WebPart { public WebPartDemo() { this.ExportMode = WebPartExportMode.All; }
private string _defaultTitle;
[Personalizable(), WebBrowsable(), WebDisplayName("默认标题"), WebDescription("列表项的默认标题"), SPWebCategoryName("新建设置")] public string DefaultTitle { get { return _defaultTitle; } set { _defaultTitle = value; } }
private bool _customBool; [Personalizable(), WebBrowsable()] public bool CustomBool { get { return _customBool; } set { _customBool = value; } }
private TextBox input; private Button btn; //编辑类主要靠这里的。。相信大家看看就明白啦 public override EditorPartCollection CreateEditorParts() { List<EditorPart> list = new List<EditorPart>();(范性) MyEditor me = new MyEditor(); me.ID = this.ID + "_me"; list.Add(me); return new EditorPartCollection(list); }
protected override void CreateChildControls() { input = new TextBox(); Controls.Add(input); btn = new Button(); btn.Text = "Add!"; btn.Click += new EventHandler(btn_Click); Controls.Add(btn); } protected override void OnPreRender(EventArgs e) { input.Text = this.DefaultTitle; } void btn_Click(object sender, EventArgs e) { if (Page.IsValid) { this.DefaultTitle = input.Text; this.SetPersonalizationDirty(); } } } }
希望对MOSS开发的哥们有帮助,其实开发就是要多练习列子。。大家一起加油吧!
相信大家对自定义工具栏很有兴趣吧,在家里研究拉一下,把自己的代码给贴出来,给大家喜欢研究MOSS的哥们研究,研究 , 其实就是继承一个编辑类就OK拉,这个自定义工具栏,在实际的MOSS开发中,很有帮助的,很多地方需要他