博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
步步为营 SharePoint 开发学习笔记系列 六、EditorPart开发
阅读量:5994 次
发布时间:2019-06-20

本文共 10488 字,大约阅读时间需要 34 分钟。

概要

System.Web.UI.WebControls.WebParts,并让这个类继承EditorPart类,并实现它的两个方法ApplyChanges和SyncChanges,简单描述:

  • ApplyChanges:是由配置界面向WebPart传值;
  • SyncChanges:是由WebPart向配置界面传值。

就是实现如下图的效果:

在我们定制的用户祥细信息webpart点击modify shared web part的显示界面上显示我们定制的用户祥细信息,显所的部门和级别.

代码设计:

新建用户祥细信息web part的user control设计,新建UserDetailUserControl.ascx:

page设计:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UserDetailUserControl.ascx.cs" Inherits="WebUserControl_UserDetailUserControl" %>
:
:
:
:
 
 

UserDetailUserControl.ascx.cs的代码设计:

using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using LearnWriteWebPart.BE;using LearnWriteWebPart.BO;using LearnWriteWebPart.Util;using LearnWriteWebPart.Interface;public partial class WebUserControl_UserDetailUserControl : System.Web.UI.UserControl{    private string parmKeyItemId = "ItemID";    ///     /// The property that holds Item id.    ///     private int ItemId    {        get        {            if (Request[this.parmKeyItemId] != null)                return Convert.ToInt32(Request[this.parmKeyItemId].ToString());            else return Constants.USERDETAIL_ID_DEFAULT;        }    }    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            BindData();        }    }    private void BindData()    {         UserBO bo = new UserBO ();        UserBE user = bo.GetUserByID(ItemId);        lblUserName.Text = user.UserAccount;        lblUserAge.Text = user.Age;        lblUserSex.Text = user.Sex;        lblUserCity.Text = user.City;    }}

web part 代码的设计:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Web.UI.WebControls.WebParts;using System.Xml.Serialization;using System.Web.UI;using LearnWriteWebPart.Util;using LearnWriteWebPart.Interface;using System.Collections;using System.ComponentModel;using Microsoft.SharePoint.WebPartPages;namespace LearnWriteWebPart.Webpart{    [ToolboxData("<{0}:UserDetailWebPart runat=server>
")] [XmlRoot(Namespace = "LearnWriteWebPart.Webpart")] public class UserDetailWebPart : System.Web.UI.WebControls.WebParts.WebPart,IUserGroup { #region [Private Variable] private string _ListName = string.Empty; private string _Url = string.Empty; private string TheListName = Constants.LISTNAME_USERDETAIL; private UserControl _userControl; private string _Dept; private string _Level; #endregion #region [Custom Properties] /// /// The property that holds how many rows will be retrieved /// [WebBrowsable(false), Personalizable(true)] public string Dept { get { return _Dept; } set { _Dept = value; } } /// /// The property that holds how many rows will be retrieved /// [WebBrowsable(false), Personalizable(true)] public string Level { get { return _Level; } set { _Level = value; } } /// /// This list naem /// [WebBrowsable(false), Personalizable(true)] public string ListName { get { return _ListName; } set { _ListName = value; } } /// /// The list Url /// [WebBrowsable(false), Personalizable(true)] public string Url { get { return _Url; } set { _Url = value; } } #endregion #region [Constructors] /// /// The sample constructor /// public UserDetailWebPart() { this.ListName = TheListName; this.Dept = Constants.DEFAULT_USERDEPT_USERDETAIL; this.Level = Constants.DEFAULT_USERLEVEL_USERDETAIL; } #endregion #region [Override Methods] /// /// Override method to OnInit method /// /// The EventsArgs object protected override void OnInit(EventArgs e) { base.OnInit(e); SetWebPartTitleAndUrlWhenAdded(this.ListName, this.Url); AddControlToWebPart(); } #endregion #region [Private Methods] /// /// Add Login Control /// private void AddControlToWebPart() { Type controlType = Type.GetType("ASP.webusercontrol_userdetailusercontrol_ascx,Web_deploy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1234567f94a516f5"); _userControl = (UserControl)this.Page.LoadControl(controlType, null); this.Controls.Add(_userControl); } /// /// Set webpart title and url /// /// /// private void SetWebPartTitleAndUrlWhenAdded(string ListName, string Url) { this.Title = this.ListName; this.TitleUrl = this.Url; } /// /// Reload Webpart /// public void ReLoadWebPart() { if (_userControl != null) { this.Controls.Remove(_userControl); this.AddControlToWebPart(); } } /// /// CreateEditorParts - Override to declare our own editor part /// ///
public override EditorPartCollection CreateEditorParts() { ArrayList editorPartArray = new ArrayList(); UserDetailEditWebPart editorPart = new UserDetailEditWebPart(); editorPart.ID = this.ID + "_editorPart"; editorPartArray.Add(editorPart); return new EditorPartCollection(editorPartArray); } #endregion }}

加入我们站点后,结果如下所示:

注意

关键是如下代码和editorPart关联起来了,重载了CreateEditorParts方法。

///         /// CreateEditorParts - Override to declare our own editor part        ///         /// 
public override EditorPartCollection CreateEditorParts() { ArrayList editorPartArray = new ArrayList(); UserDetailEditWebPart editorPart = new UserDetailEditWebPart(); editorPart.ID = this.ID + "_editorPart"; editorPartArray.Add(editorPart); return new EditorPartCollection(editorPartArray); }

接着我们新建UserDetailEditWebPart.cs

代码如下:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Web.UI.WebControls;using Microsoft.SharePoint;using System.Web.UI.WebControls.WebParts;using LearnWriteWebPart.Util;using LearnWriteWebPart.Interface;namespace LearnWriteWebPart.Webpart{    public class UserDetailEditWebPart : EditorPart    {        private DropDownList ddlUserDept;        private DropDownList ddlUserLevel;        public override bool ApplyChanges()        {            try            {                UserDetailWebPart userDetailWebPart = this.WebPartToEdit as UserDetailWebPart;                if (userDetailWebPart != null)                {                    userDetailWebPart.Dept = ddlUserDept.SelectedValue;                    userDetailWebPart.Level = ddlUserLevel.SelectedValue;                    userDetailWebPart.ReLoadWebPart();                }                return true;            }            catch            {                return false;            }        }        public override void SyncChanges()        {            this.EnsureChildControls();            // Get a reference to the CommentsEditorPart web part we are editing            UserDetailWebPart userDetailWebPart = this.WebPartToEdit as UserDetailWebPart;            if (userDetailWebPart != null)            {                if (!string.IsNullOrEmpty(userDetailWebPart.Dept))                    ddlUserDept.SelectedValue = userDetailWebPart.Dept;                if (!string.IsNullOrEmpty(userDetailWebPart.Level))                    ddlUserLevel.SelectedValue = userDetailWebPart.Level;            }        }        ///         /// Create dropdownlist for annoucement type        ///         protected override void CreateChildControls()        {            base.CreateChildControls();            this.Title = Constants.LISTNAME_USERDETAIL;            BindDept();            BindLevel();            this.Controls.Add(CreateLiteral("部门 
")); this.Controls.Add(ddlUserDept); this.Controls.Add(CreateLiteral("级别
")); this.Controls.Add(ddlUserLevel); } private void BindDept() { ddlUserDept = new DropDownList(); List
listItem = new List
(); listItem.Add(new ListItem("HR Dept", "HR Dept")); listItem.Add(new ListItem("FI Dept", "FI Dept")); listItem.Add(new ListItem("IT Dept", "IT Dept")); ddlUserDept.DataSource = listItem; ddlUserDept.DataBind(); } private void BindLevel() { ddlUserLevel = new DropDownList(); List
listItem = new List
(); listItem.Add(new ListItem("Primary", "Primary")); listItem.Add(new ListItem("Intermediate", "Intermediate")); listItem.Add(new ListItem("Senior", "Senior")); ddlUserLevel.DataSource = listItem; ddlUserLevel.DataBind(); } ///
/// /// ///
///
private Literal CreateLiteral(string text) { Literal lit = new Literal(); lit.Text = text; return lit; } }}

关键还是重载了ApplyChanges()和SyncChanges()这两个方法.加上去,点击Modify Shared Wep Part后显示的结果如我们上图所示.

接下来讲解share point Time Job的开发。

转载地址:http://mnqlx.baihongyu.com/

你可能感兴趣的文章
find the mincost route(最小环,最短路,floyd)
查看>>
TCP 的那些事儿(上)
查看>>
Discuz!NT3.6与网站整合(操作用户信息)解决方案
查看>>
【今日推荐】10大流行的 Metro UI 风格的 Bootstrap 主题和模板
查看>>
Swift - 实现拨打电话
查看>>
在线代码编辑、保存与运行网址推荐
查看>>
博客园添加访问人数统计
查看>>
Yii2 RBAC 用到的表
查看>>
在使用DBMS_LOB.WRITEAPPEND()追加Clob内容的时候,报数字或值异常
查看>>
hibernate 在做更新和删除的时候一定要把事务开启
查看>>
将已有jar添加至本地maven仓库
查看>>
获取用户的真实ip
查看>>
不同平台的线程并发接口对比
查看>>
在Ubuntu14.4(32位)中配置I.MX6的QT编译环境
查看>>
BZOJ 3530: [Sdoi2014]数数 [AC自动机 数位DP]
查看>>
墨卡托投影、高斯-克吕格投影、UTM投影及我国分带方法
查看>>
Android中通过反射来设置Toast的显示时间
查看>>
Vysor Pro破解助手
查看>>
理顺FFT
查看>>
003-spring结合java类调用quartz
查看>>