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

  • Home
  • SEARCH
  • 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 8233947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:18:31+00:00 2026-06-07T18:18:31+00:00

I have a table with about 3 items. I wish to populate the Dropdown

  • 0

I have a table with about 3 items. I wish to populate the Dropdown List using that table. But i have a condition that i want to show only 2 items in the Dropdown List. How can it be done?

  • 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-07T18:18:33+00:00Added an answer on June 7, 2026 at 6:18 pm

    You could use a view model:

    public class MyViewModel
    {
        public string SelectedItemId { get; set; }
        public IEnumerable<SelectListItem> Items { get; set; }
    }
    

    and then take the first 2 items (obviously if your requirements is to take some other 2 items based on some condition you could chain with the .Where() extension method in order to filter first before calling .Take()):

    public ActionResult Index()
    {
        var model = new MyViewModel();
        model.Items = db.Items.Take(2).ToList().Select(x => new SelectListItem
        {
            Value = x.Id,
            Text = x.SomeText
        });
        return View(model);
    }
    

    The view is standard stuff, simply call to the DropDownListFor helper:

    @model MyViewModel
    @Html.DropDownListFor(x => x.SelectedItemId, Model.Items)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have lists of about 20,000 items that I want to insert into a
i have a table with about 200,000 records. i want to add a field
I have a table with about 100k records and I want to delete some
I have a Fusion Table of about 1000 entries, and I show them on
I have a MySQL table with about 5,000,000 rows that are being constantly updated
I have a table of play data that I'm using for a prototype. I'm
Back story i have a table that stores cached times, and currently has about
Currently, I have a table view that the user can add items and delete
So I have a table with a field that I wish to work with
I have a tableLayout that is created programmatically, about 23 items are added to

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.