JG Vimalan's Blog

It is all about coding!

People Editor in custom webpart in MOSS 2007

Hi, 

The following code snippet shows how to add PeopleEditor control in custom sharepoint webpart. It also shows how to read values from people editor. 

    public class EmployeeDetails : WebPart
    {
        #region declarations
        PeopleEditor _DisplayName = null;
         . . .
        //In the business logic, use this method to get the user selected in the
        //people editor
        private SPUser GetuserName(PeopleEditor userName, SPWeb web)
        {
            SPUser user = null;

            foreach (PickerEntity pe in userName.Entities)
            {
                user = web.AllUsers[pe.Key];
            }
            return user;
        }
    protected override void CreateChildControls()
     {
         . . .
         
            TableRow EmployeeName = new TableRow();

            TableCell EmployeeNameLabel = new TableCell();
            TableCell EmployeeNameControl = new TableCell();
            EmployeeNameLabel.Text = “Employee Name:”;

            EmployeeNameLabel.HorizontalAlign = HorizontalAlign.Right;
            EmployeeNameLabel.CssClass = “ms-formlabel”;
            _DisplayName = new PeopleEditor();
            _DisplayName.AllowTypeIn = true;
            _DisplayName.AllowEmpty = false;
            _DisplayName.EnableBrowse = true;
            _DisplayName.ID = “peopleID”;
            _DisplayName.MultiSelect = false;
            _DisplayName.ValidatorEnabled = true;

            EmployeeNameControl.CssClass = “ms-formbody”;
            EmployeeNameControl.Controls.Add(_DisplayName);
            ….

     //TO DO: Render the controls 

OutPut: 

Once this webpart is deployed, you will get output as shown below,

PE

Happy Coding!!!

JG Vimalan

Advertisements

August 11, 2009 - Posted by | SharePoint

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: