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 6239261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:21:42+00:00 2026-05-24T11:21:42+00:00

I create a dropdownlist from Enum. public enum Level { Beginner = 1, Intermediate

  • 0

I create a dropdownlist from Enum.

public enum Level
{
    Beginner = 1,
    Intermediate = 2,
    Expert = 3
}

here’s my extension.

    public static SelectList ToSelectList<TEnum>(this TEnum enumObj)
    {

        IEnumerable<TEnum> values = Enum.GetValues(typeof(TEnum)).Cast<TEnum>();

        var result = from TEnum e in values
                     select new { ID = (int)Enum.Parse(typeof(TEnum), e.ToString()), Name = e.ToString() };

        var tempValue = new { ID = 0, Name = "-- Select --" };


        return new SelectList(result, "Id", "Name", enumObj);
    }

the problem I have is to insert antoher item into IEnumerable. I just could not figure out how to do it. Can someone please modify my code to insert “–select–” to the top.

  • 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-05-24T11:21:43+00:00Added an answer on May 24, 2026 at 11:21 am

    You can’t modify a IEnumerable<T> object, it only provides an interface to enumerate elements. But you could use .ToList() to convert the IEnumerable<T> to a List<T>.

    I’m not sure if this is what you want:

    public static SelectList ToSelectList<TEnum>(this TEnum enumObj)
    {
    
        IEnumerable<TEnum> values = Enum.GetValues(typeof(TEnum)).Cast<TEnum>();
    
        var result = from TEnum e in values
                     select new { ID = (int)Enum.Parse(typeof(TEnum), e.ToString()), Name = e.ToString() };
    
        var tempValue = new { ID = 0, Name = "-- Select --" };
    
        var list = result.ToList(); // Create mutable list
    
        list.Insert(0, tempValue); // Add at beginning of list
    
        return new SelectList(list, "Id", "Name", enumObj); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Based on this post: How do you create a dropdownlist from an enum in
I'd like to create a dropdownlist from following structure List<KeyValuePair<long, string>> sponsori = new
i have create an imagelist with 20 bitmap inside and a dropdownlist value from
I've created a SelectList from a enum. The enum has a description, and the
I would like to create a DropDownList containing 2 items: Part Name and NSN
I need to create a .NET control (in ASP.NET) from a string that represents
I have a dropdownlist for which I am loading data from excel. Excel has
I'd like to create a text field with a dropdown list that lets the
I need to create a form with, half linear view (textboxes and dropdownlists in
create table person ( name varchar(15), attr1 varchar(15), attr2 varchar(1), attr3 char(1), attr4 int

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.