Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need help on how to display a default message in dropdownlist that says <-Please select Requestor-> instead of displaying a name by default when page loads.

What I have tried:

Here is my asp code

XML
<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 method

C#
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>();
     }
}
Posted
Updated 23-Dec-19 17:37pm
Comments
MadMyche 23-Dec-19 15:27pm    
Please do not repost the same question; and try to understand that many people are out on holidays right now and may not be back for a couple of weeks still.

Original Q: https://www.codeproject.com/Questions/5254672/How-do-I-show-a-message-inside-dropdownlist
Member 11403304 23-Dec-19 16:27pm    
MadMyche please accept my apology.

1 solution

use selected index
use selected index 
use selected index 
use selected index 
use selected index 
use selected index 
use selected index 
use selected index 
use selected index 
 
Share this answer
 
Comments
Member 11403304 27-Dec-19 14:57pm    
I am not sure how to add what you suggested selected index to my code. Please help.

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