Codebanking.com Bank your code here...
HOME REGISTER TECHNICAL Q&A GENERAL Q&A SUBMIT CODE SNIPPET LOGIN
 
 Topics
 Tech Feeds
 Tech Fun

How to load values in peopleeditor control in sharepoint custom application page?

Add assembly directive in custom application page

<(add percentage)@ Register TagPrefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"(add percentage)>


Here is the control

                                                ValidatorEnabled="true" ID="Appsperson" runat="server" ShowCreateButtonInActiveDirectoryAccountCreationMode="true"
                                                SelectionSet="User" Visible="true" />


Here is the code for loading control on page load event

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { 
                SPSite oSiteCollection = SPContext.Current.Site;
                SPWeb spCurrentWeb = oSiteCollection.OpenWeb();    
   
               using (SPSite site = new SPSite(spCurrentWeb.Url))
               {
                    site.AllowUnsafeUpdates = true;
                    using (SPWeb web = site.OpenWeb())
                    {
                        web.AllowUnsafeUpdates = true;

                        list = web.Lists["listname"];
                        string ItemId = Request.QueryString["ItemId"];
                       SPListItem  item = list.GetItemById(Convert.ToInt32(ItemId));

                           if (item["EditContact"] != null) // Editcontact is column name
                            {
                                Appsperson.CommaSeparatedAccounts = LoadPeopleEditor("EditContact", item);
                            }

                       }

                  }

             }

      }


 private string LoadPeopleEditor(string fieldName, SPListItem spListItem)
        {
            string peopleEditorValue = string.Empty;
            SPFieldUserValueCollection spFieldUserValueCollection = (SPFieldUserValueCollection)spListItem[fieldName];
            foreach (SPFieldUserValue spFieldUserValue in spFieldUserValueCollection)
            {
                if (spFieldUserValue != null)
                {
                    string lookUpVal = string.Empty;
                    if (spFieldUserValue.User != null)
                        lookUpVal = spFieldUserValue.User.LoginName;
                    else
                        lookUpVal = spFieldUserValue.LookupValue;
                    peopleEditorValue += lookUpVal;
                    peopleEditorValue += ",";
                }
            }
            peopleEditorValue = peopleEditorValue.Substring(0, peopleEditorValue.Length - 1);
            return peopleEditorValue;
        }


Comments Posted:
No Comments Posted
Please login for leave your comments
 
 2010 codebanking.com      contactus@codebanking.com