Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8151515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:24:57+00:00 2026-06-06T15:24:57+00:00

I have got a enum public enum TypeDesc { [Description(Please Specify)] PleaseSpecify, Auckland, Wellington,

  • 0

I have got a enum

public enum TypeDesc
{
[Description("Please Specify")]
PleaseSpecify,
Auckland,
Wellington,
[Description("Palmerston North")]
PalmerstonNorth,
Christchurch
}

I am binding this enum to drop down list using the following code on page_Load

protected void Page_Load(object sender, EventArgs e)
        {
            if (TypeDropDownList.Items.Count == 0)
            {
                foreach (TypeDesc newPatient in EnumToDropDown.EnumToList<TypeDesc>())
                {
                 TypeDropDownList.Items.Add(EnumToDropDown.GetEnumDescription(newPatient));
                }
            }
        }

public static string GetEnumDescription(Enum value)
        {
            FieldInfo fi = value.GetType().GetField(value.ToString());

            DescriptionAttribute[] attributes =
                (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);

            if (attributes != null && attributes.Length > 0)
                return attributes[0].Description;
            else
                return value.ToString();
        }

        public static IEnumerable<T> EnumToList<T>()
        {
            Type enumType = typeof(T);

            // Can't use generic type constraints on value types,
            // so have to do check like this
            if (enumType.BaseType != typeof(Enum))
                throw new ArgumentException("T must be of type System.Enum");

            Array enumValArray = Enum.GetValues(enumType);
            List<T> enumValList = new List<T>(enumValArray.Length);

            foreach (int val in enumValArray)
            {
                enumValList.Add((T)Enum.Parse(enumType, val.ToString()));
            }

            return enumValList;
        }

and my aspx page use the following code to validate

            <asp:DropDownList ID="TypeDropDownList" runat="server" >
            </asp:DropDownList>
            <asp:RequiredFieldValidator ID="TypeRequiredValidator" runat="server" ControlToValidate="TypeDropDownList" ErrorMessage="Please Select a City" Text="<img src='Styles/images/Exclamation.gif' />"
                ValidationGroup="city"></asp:RequiredFieldValidator>

But my validation is accepting “Please Specify” as city name. I want to stop user to submit if the city is not selected.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:24:59+00:00Added an answer on June 6, 2026 at 3:24 pm

    Add a please specify before adding the enum items.

     TypeDropDownList.Items.Add("Please Specify","");
     foreach (TypeDesc newPatient in EnumToDropDown.EnumToList<TypeDesc>())
     {
        TypeDropDownList.Items.Add(EnumToDropDown.GetEnumDescription(newPatient), newPatient.ToString());
     }
    

    Remove “Please Specify” from the enum

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got following code: I have a enum: public enum HardwareInterfaceType { Gpib
I've got the class object for an enum (I have a Class<? extends Enum>
The system have a plain enum like this, public enum SomeEnum : short {
I'm writing some Enum functionality, and have the following: public static T ConvertStringToEnumValue<T>(string valueToConvert,
there. I have the foloowing class definition: [Serializable] public enum FilterType { [XmlEnum(1)] Text
I'm new to enum. I've got this enum: public enum Categories { Animals, Animations,
I've got an enum and a Foo class: public enum Type { Arithmetic, Fraction,
I have the following enumeration: public enum AuthenticationMethod { FORMS = 1, WINDOWSAUTHENTICATION =
Let's assume we've got the following Java code: public class Maintainer { private Map<Enum,
I have a question about the IEnumerator.GetEnumerator() method. public class NodeFull { public enum

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.