Click here to Skip to main content
16,020,677 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is what I am trying to do. When page loads and RequestorDropDownList is populated the first name is displayed.
What I want to do is instead of the name displayed, I want to display message <-Please select Requestor->.
When the user click on dropdownlist and select a name, then the name selected by the user will be displayed.

I have my method here. What do I need to add and how?

I also played with this code inside the method but it did not work

C#
List<GetRequestorInfoModel> requestors = new List<GetRequestorInfoModel>();
RequestorDropDownList.Items.Clear();
DropDownList firstRequestor = new DropDownList();
firstRequestor.Text = "<-Please select Requestor->";
firstRequestor.SelectedIndex = 0;


What I have tried:

My aspx code

C#
<asp:DropDownList ID="RequestorDropDownList" runat="server" Font-Size="8.25pt" 
     Height="20px" ToolTip="Requestor" Width="160px" SelectMethod="GetRequestorEmail"
     DataTextField="DisplayName" DataValueField="Email">
</asp:DropDownList>


Here is my code behind

C#
#region Requestor dropdownlist
        public async Task<IEnumerable<GetRequestorInfoModel>> GetRequestorEmail()
        {
            try
            {
                var requestors = await FTACaseReseting.Controllers.RequestorInfoController.GetAllRequestorInfoes();
                return requestors.OrderBy(x => x.DisplayName);
            }
            catch (Exception ex)
            {
                string errorMsg = string.Format("An error has occured in {0}. \nException:\n{1}", "PopulateRequestorComboBox()", ex.Message);
                Response.Write("<script>alert(" + HttpUtility.JavaScriptStringEncode(errorMsg, true) + ")</script>");
                return Enumerable.Empty<GetRequestorInfoModel>();
            }
        }
        #endregion
Posted
Updated 31-Dec-19 0:20am
v2

1 solution

Maybe you can convert your requestors result into List<> then add what you need to show and then return.
For example :

public IEnumerable<Person> GetRequestorEmail2()
{

  List<Person> personList = new List<Person>();
  personList.Add(new Person { Something = "asd", Something2 = "0" }); 
  personList.Add(new Person { Something = "asd", Something2 = "1" });

//here add what you want 
  personList.Add(new Person {Something= "<-Please select Requestor->", Something2="-1"});

  return personList.OrderBy(x=>x.Something);

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900