zoukankan      html  css  js  c++  java
  • sps 2007 小问题1:人员选择器PeopleEditor如何使用

    要在MOSS中开发一个有用户选择功能的页面或webpart,就要用到PeopleEditor 控件了

    页面声明如下:
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Import Namespace="Microsoft.SharePoint" %>
    <SharePoint:PeopleEditor id="PeopleEditor1" runat="server"
        SelectionSet
    ="User"
        ValidatorEnabled
    ="true"
        AllowEmpty 
    = "false"
        MultiSelect 
    = "true"
    />
    这样,就能显示出标准的用户选择界面了.

    接下来,我们如何获取选择的用户数据呢?
     ArrayList list = PeopleEditor1.ResolvedEntities ;
     
    //获取id和显示名称
    foreach (Microsoft.SharePoint.WebControls.PickerEntity p in list)
    {
       
    string userId = p.EntityData["SPUserID"].ToString();
       
    string DisplayName = p.EntityData["DisplayName"].ToString();               
     }           
    //获取帐号
    ArrayList selectedAccoutList = PeopleEditor1.Accounts;
     
    string selectedAccouts2 = PeopleEditor1.CommaSeparatedAccounts;

    设置初始选中用户:
     PeopleEditor1.CommaSeparatedAccounts = @"JYSERVER\spsadmin,JYSERVER\administrator";

    测试代码需要在moss的环境中运行,页面放入_layouts文件夹,或写到webpart中。

    下面是一个完整的测试用webpart:
    //test code by jianyi0115@163.com
    // 2008-11-10
    //
    //
    using System;
    using System.Collections;
    using System.Text;
    using sharepoint = Microsoft.SharePoint.WebControls ;
    using wss = Microsoft.SharePoint.WebPartPages;
    using System.Web.UI.WebControls  ;
    using System.Runtime.InteropServices;
    using Microsoft.SharePoint;

    namespace PeoplePickerTest
    {
        [Guid(
    "8D64A4D3-8C9F-4a44-9720-611A701C0B79")]
        
    public class MyPeoplePicker : wss.WebPart                
        {
            
    private Microsoft.SharePoint.WebControls.PeopleEditor PeopleEditor1;
            
    private Button btn;

            
    protected override void CreateChildControls()
            {
                
    base.CreateChildControls();
                PeopleEditor1 
    = new Microsoft.SharePoint.WebControls.PeopleEditor();
                Controls.Add(PeopleEditor1);
                btn 
    = new Button();
                btn.Text 
    = "test";
                Controls.Add(btn);
                btn.Click 
    += new EventHandler(btn_Click);
             }
     
            
    void btn_Click(object sender, EventArgs e)
            {
                Page.Response.Write( PeopleEditor1.CommaSeparatedAccounts );

                ArrayList list 
    = PeopleEditor1.ResolvedEntities ;
                
    //获取id和显示明
                foreach (Microsoft.SharePoint.WebControls.PickerEntity p in list)
                {
                    
    string userId = p.EntityData["SPUserID"].ToString();
                    
    string DisplayName = p.EntityData["DisplayName"].ToString();               
                }           

                
    //获取帐号
                ArrayList selectedAccoutList = PeopleEditor1.Accounts;
                
    string selectedAccouts2 = PeopleEditor1.CommaSeparatedAccounts;
                
    //设置值
                PeopleEditor1.CommaSeparatedAccounts = @"JYSERVER\spsadmin,JYSERVER\administrator";
            }
        }
    }

  • 相关阅读:
    Java实体书写规范
    Mybatis配置中遇到的问题和问题分析
    Ubuntu下eclipse的Extjs提示插件安装
    Ubuntu中root用户和user用户的相互切换
    ubuntu下启动和关闭tomcat的简单方法
    Ubuntu上安装Maven Eclipse以及配置
    IE8兼容<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    心情
    更改Eclipse下Tomcat的部署目录
    Tomcat:IOException while loading persisted sessions: java.io.EOFException 解决
  • 原文地址:https://www.cnblogs.com/jianyi0115/p/955452.html
Copyright © 2011-2022 走看看