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";
            }
        }
    }

  • 相关阅读:
    JS函数的定义与调用方法
    一次完整的浏览器请求流程
    【前端安全】JavaScript防http劫持与XSS
    深入理解display属性
    前端开发人员需要了解的CSS原理
    第 10 章 文件系统及实现
    第 9 章 虚拟内存管理
    第 8 章 内存管理策略
    第 7 章 死锁
    第 6 章 同步
  • 原文地址:https://www.cnblogs.com/jianyi0115/p/955452.html
Copyright © 2011-2022 走看看