Monday, January 16, 2012

Use People Picker in custom web part

Try the following
Include the Tagprefix at the top in your webpart ascx file where there are all the tag prefixes.
Then include the PeopleEditor wherever you want.
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<SharePoint:PeopleEditor ID="spPeoplePicker" runat="server" Width="350" SelectionSet="User" />

Insert something like this in code behind
if (spPeoplePicker.ResolvedEntities.Count > 0)
                    {
                        PickerEntity selectedEntity = (PickerEntity)spPeoplePicker.ResolvedEntities[0];

UserProfile profile= upm.GetUserProfile(selectedEntity.Key);
}

Modify as per your requirement.
Also refer the following link

Yes, you can populate a dropdown with values from a list field
<asp:DropDownList ID="ddlDropDown" runat="server" >
    </asp:DropDownList>



In the code behind include
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["ListName"];
                SPListItemCollection items= list.GetItems();

                if (items!= null)
                {
                   
                    foreach (SPListItem item in items)
                    {
                        if (item["FieldName"] != null)
                            ddlDropDown.Items.Add(item["FieldName"].ToString());
                    }
                }