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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:50:24+00:00 2026-05-15T09:50:24+00:00

I almost have this solved but need a little push. Here’s what I have:

  • 0

I almost have this solved but need a little push.

Here’s what I have:

In the database I have a field called active that is a bit field (True/False)

I have placed a dropdownlist on the View form like this:

<%= Html.DropDownList("lstActive", new SelectList((IEnumerable)ViewData["ActiveList"])) %>

In my controller, I simply have this code to generate the True/False in the dropdown:

        List<string> activeList = new List<string>();
        activeList.Add("True");
        activeList.Add("False");

        ViewData["ActiveList"] = new SelectList(activeList);

I want to bind to the field in the database called active and select it in the dropdown. When I view it like this I get this:

alt text http://rjmueller.net/sitesimages/temp/dropdown.gif

So the questions are these:

Obviously I am not pointing to the Value and Text property but what is that in this case?
And how do I select the value that is in the database?

Any help would be appreciated.

  • 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-15T09:50:25+00:00Added an answer on May 15, 2026 at 9:50 am

    Here’s a couple of suggestions for you.

    First, your DropdownList’s name is “lstActive”, so if you create a List<SelectListItem> called “lstActive” and pass that back in ViewData, you don’t have to do anything fancy with boxing. Then your declaration looks like:

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

    easy, huh?

    In your controller, you create your List. Here’s a method I’ve used:

        private List<SelectListItem> GetAccounts(User user)
        {
            var items = new List<SelectListItem>();
            foreach (Account account in user.Accounts)
            {
                var item = new SelectListItem();
                item.Text = account.Name;
                item.Value = account.AccountId.ToString();
                if (ActiveAccount == account.AccountId)
                    item.Selected = true;
                items.Add(item);
            }
            return items;
        }
    

    Basically, what I’m trying to point out is that you can set a property on your SelectListItem that you wish to be displayed as selected. Here, I’m using my own code for Users and Accounts, but you’d substitute your own data based on your db query.

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

Sidebar

Related Questions

I have almost the worst spec in the world. An application that exists and
I have a right outer join, that almost does what I want... SELECT users_usr.firstname_usr,
I have a table (T1) in t-sql with a column (C1) that contains almost
Here's the problem: I have an (almost) empty aspx page and I want to
I need help with a oracle query. Here is my setup: I have 2
I have several input and option elements on my page, each (well almost) have
In the STL almost all containers have an erase function. The question I have
Some development skills, like refactoring operations, feel like they have an almost unlimited pontential
I have a table with almost 800,000 records and I am currently using dynamic
I have two insert statements, almost exactly the same, which run in two different

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.