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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:39:07+00:00 2026-05-12T17:39:07+00:00

I want to specify a value for each option in the my select list

  • 0

I want to specify a value for each option in the my select list box but I am generating it with an html helper.

So I have this

<%= Html.DropDownList("DropDownList") %>  

// controller

ViewData["DropDownList"] = new SelectList(MyClass.GenerateListBox());

// MyClass

        public static List<string> GenerateListBox()
        {
            List<string> listBox= new List<string>();
            listBox.Add("Bye");
            listBox.Add("hi");
            listBox.Add("something");

            return listBox;
        }

So I see that SelectList has a “stringDataField” but it is only a stringnot a list so now really sure what I have to change.

Do I have to make some sort of other list?

Thanks

  • 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-12T17:39:07+00:00Added an answer on May 12, 2026 at 5:39 pm

    Use this constructor instead:

    ViewData["DropDownList"] = new SelectList(GenerateListBox(), "Value", "Text");
    
    public static List<SelectListItem> GenerateListBox()
    {
        List<SelectListItem> listBox = new List<SelectListItem>();
        listBox.Add(new SelectListItem { Text = "bye", Value = "byeValue" });
        listBox.Add(new SelectListItem { Text = "hi", Value = "hiValue" });
        listBox.Add(new SelectListItem { Text = "something", Value = "somethingValue" });
    
        return listBox;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form.html: <div id=tag_option> <li><label for=id_customer_type>Customer type:</label> <select id=id_customer_type class=required name=customer_type> <option
ASP.NET For each appSetting I use, I want to specify a value that will
I want to specify an argument in an attribute, like this: [OutputCache(Duration = GlobalSettings.GlobalVar)]
I have a base class in which I want to specify the methods a
I have a Java WebStart application for which I want to specify that the
I have a custom behavior for a service where I want to specify a
I have some user controls which I want to specify properties and methods for.
So, this question may be a little vague, but I have constant discussions about
I have a HTML Table which in which i want to manipulate using JQuery
I have a view like this: CREATE VIEW MyView AS SELECT Column FROM Table

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.