none
How do you display a default message in a DropDownList? RRS feed

  • Question

  • I would like to display a message in dropdownlist that says <-Please select Requestor-> instead of displaying a name by default when page loads.

    Here is my asp code

    <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

    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>();
                }
            }

     

    Monday, December 23, 2019 5:54 PM