0

I have customized the sharepoint list Newfor/Editform/dispform.aspx pages with my custom page.

Below is the screenshot for the same.

In My custom for.aspx page i have 2 Sharepoint people picker controls

--> I was sucessfully able to add the users to the people picker in Newform.aspx page. but when i click on Edit form.aspx page i am not sure how to fetch the people picker values entered by the user.

Note: I was sucessfully able to fetch the other data like Dropdown,datepicker,textbox like below on Load data()

Data type of the People picker in my content type is Peopleorgroup. enter image description here

Code which i have tried

 protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
              LoadData()
              }
        }
private void LoadData()
        {
            var list = SPContext.Current.Web.Lists[new Guid(Request.QueryString["list"])];
            var itemId = 0;
            if (string.IsNullOrEmpty(Request.QueryString["id"]) == false)
            {
                int.TryParse(Request.QueryString["id"], out itemId);
            }
            if (itemId != 0)
            {
                var listItem = list.GetItemById(itemId);
                ddlNotificationType.SelectedIndex = ddlNotificationType.Items.IndexOf(ddlNotificationType.Items.FindByText((listItem["NotificationType"] == null) ? string.Empty : listItem["NotificationType"].ToString()));
                txtTitle.Text = (listItem["Title"] == null) ? string.Empty : listItem["Title"].ToString();
                ddlTaskFrequency.SelectedIndex = ddlTaskFrequency.Items.IndexOf(ddlTaskFrequency.Items.FindByText((listItem["TaskFrequency"] == null) ? string.Empty : Convert.ToString(listItem["TaskFrequency"])));
                TStartDate.Text = (listItem["StartDate"] == null) ? string.Empty : listItem["StartDate"].ToString();
                ChkNoofDays.Checked = Convert.ToBoolean((listItem["DuedateChecked"] == null) ? string.Empty : Convert.ToString(listItem["DuedateChecked"]));
}
}


*/Button clicked is fired when saving an item*/
 protected void btnSchedule_Click(object sender, EventArgs e)
        {
            var list = SPContext.Current.Web.Lists[new Guid(Request.QueryString["list"])];
            var itemId = 0;
            if (string.IsNullOrEmpty(Request.QueryString["id"]) == false)
            {
                int.TryParse(Request.QueryString["id"], out itemId);
            }
            SPListItem listItem = null;
            if (itemId == 0)
            {
                listItem = list.AddItem();
            }
            else
            {
                listItem = list.GetItemById(itemId);
            }


            SPFieldUserValueCollection usercollection = GetPeopleFromPickerControl(userPicker, mySiteWeb);
            SPFieldUserValueCollection Backusercollection = GetPeopleFromPickerControl(pplBackup, mySiteWeb);
            String Notificationtype = Convert.ToString(ddlNotificationType.SelectedItem.Text);
            String TaskTitle = Convert.ToString(txtTitle.Text);
            String TaskFrequency = ddlTaskFrequency.SelectedItem.Text;
            String Startdate = Convert.ToString(TStartDate.Text);
            String DuedateChecked = Convert.ToString(ChkNoofDays.Checked);
            listItem["NotificationType"] = Notificationtype;
            listItem["Title"] = TaskTitle;
            listItem["PointOfContact"] = usercollection;
            listItem["BackupPointOfContact"] = Backusercollection;
            listItem["TaskFrequency"] = TaskFrequency;
            listItem["StartDate"] = Startdate;
            listItem["DuedateChecked"] = DuedateChecked;
            listItem["NoofDays"] = Noofdays;
            listItem["DueDate"] = Duedate; 
             listItem.Update();
            Context.Response.Write("<script language='javascript'> window.frameElement.commitPopup();</script>");
            Context.Response.Flush();
            Context.Response.End();
}
1

Hey Guys I made it after scratching my head :-)... Thanks to Google

Below is the code in order to do the same.

 if (listItem["PointOfContact"] != null)
                {
                    char[] to_splitter = { ';' };
                    string to_list = listItem["PointOfContact"].ToString(); // Reads value stored in SPList. (i.e., "Domain\User1; Domain\User2")
                    string[] arr = to_list.Split(to_splitter);
                    string user = string.Empty;
                    System.Collections.ArrayList entityArrayList = new System.Collections.ArrayList();
                    for (int i = 1; i < arr.Length; i++)
                    {
                        if ((i % 2) != 0)
                        {
                            user = arr[i].Substring(arr[i].IndexOf("#") + 1);
                            PickerEntity entity = new PickerEntity();
                            entity.Key = user;
                            entity = userPicker.ValidateEntity(entity);
                            entityArrayList.Add(entity);
                        }
                    }
                    userPicker.UpdateEntities(entityArrayList);
                }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.