How do I make my method to populate listbox? RRS feed

  • Question

  • I have a listbox that I want to be populated when page loads. The listbox will be populated with names of people. These names are associated each person's email. My method is not working. When page loads the listbox is empty.

    When I hover mouse over object staffEmails I can see count = 16. there are 16 names and the emails. When I expand the staffEmails I see [0] {FTACaseReseting.Models.GetRequestorInfoModel}. When I expand this I see DisplayName "Jim, Doe" Email "". However my listbox is not populated with this name or other names.  

    I am not sure how to change my method so the listbox is populated with the names. Please help

    Here is my method. 

     public async void PopulateAdditionalStaffEmailListBox()
                    List<GetRequestorInfoModel> staffEmails = new List<GetRequestorInfoModel>();
                    staffEmails = await FTACaseReseting.Controllers.RequestorInfoController.GetAllRequestorInfoes();
                    staffEmails = staffEmails.OrderBy(x => x.DisplayName).ToList();
                    AdditionalStaffEmailListBox.DataSource = staffEmails;
                    AdditionalStaffEmailListBox.DataSource = "DisplayName";
                    AdditionalStaffEmailListBox.DataValueField = "Email";
                    //Clear all selections in the listbox after populating
                catch (Exception ex)
                    string errorMsg = string.Format("An error has occured in {0}. \nException:\n{1}", "AdditionalStaffEmailListBox()", ex.Message);
                    Response.Write("<script>alert('" + errorMsg + "')</script>");

    • Edited by winkimjr2 Thursday, December 19, 2019 3:00 PM Changed question text
    Thursday, December 19, 2019 2:45 PM