SharePoint 新建一个编辑的web Part代码

代码示例如下:

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;
namespace LoisAndClark.AspNetExample
{
public class NormalEditorPart : EditorPart
{
TextBox _txtNormalBox;
protected override void CreateChildControls()
{
_txtNormalBox = new TextBox();
_txtNormalBox.ID = “txtNormalBox”;
_txtNormalBox.Text = “[Custom editor part]”;
_txtNormalBox.TextMode = TextBoxMode.MultiLine;
_txtNormalBox.Rows = 5;
Controls.Add(_txtNormalBox);
}
public override bool ApplyChanges()
{
NormalPart objNormal = (NormalPart)WebPartToEdit;
objNormal.NormalValue = _txtNormalBox.Text;
return true;
}
public override void SyncChanges()
{
EnsureChildControls();
NormalPart objNormal = (NormalPart)WebPartToEdit;
_txtNormalBox.Text = objNormal.NormalValue;
}
}
}

要继承EditorPart这个类,重载CreateChildControls,ApplyChanges,SyncChanges方法,

不只是textbox控件,也可以是其它如:GridView,label等等

posted @ 2011-03-08 13:32  spring yang  阅读(492)  评论(2编辑  收藏  举报