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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:28:48+00:00 2026-05-28T04:28:48+00:00

So if Set up a DropDownList where Text: people names (string) and Value: studentID

  • 0

So if Set up a DropDownList where Text: "people names" (string)and Value:studentID (int). in my view like this (assuming myDDL is data from code-behind placed in the viewbag)

     @Html.DropDownList("myDDL", (IEnumerable<SelectListItem>)ViewBag.myDDL,  
     "Select Stuff", new Dictionary<string,object>{
      {"class","dropdowns"},{"id","myDDL"}})  

What is the value of “Select Stuff” which is an optional label that appears at the beginning of the dropdown list?

I’d like the value because it if no value is selected then I’d like to get all the data.

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-28T04:28:48+00:00Added an answer on May 28, 2026 at 4:28 am

    It’s empty and it’s always the first option of the dropdown, so make sure that you are binding it to a non-nullable property in the postback action:

    <select name="selectedValue">
        <option value="">Select Stuff</option>
        ...
    </select>
    

    Also you seem to be using myDDL as both the first argument and the second of the dropdownlist helper which is wrong. The first argument is a property that would be used to get the selected value. The second is the available values and must be an IEnumerable<SelectListItem>.

    So something like this would make more sense:

    @Html.DropDownList(
        "selctedValue",
        (IEnumerable<SelectListItem>)ViewBag.myDDL,
        "Select Stuff", 
        new { @class = "dropdowns", id = "myDDL" }
    )
    

    But what would really make sense and what I would recommend you is to get rid of this ViewBag and use a view model and the strongly typed version of this helper:

    @model MyViewModel
    ...
    @Html.DropDownListFor(
        x => x.SelectedValue,
        Model.MyDdlItems,
        "Select Stuff", 
        new { @class = "dropdowns", id = "myDDL" }
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Attempting something like public string MyText { get {return lbl.Text;} set {lbl.Text = value;}}
When I set fckEditor to Some Value like fckDescription.Value = Description Text; It creates
I have a dropdownlist with values -1,1,2 and text A,B,C i wanna set B
As the question says, how do I set the value of a DropDownList control
Ok guys, so I read this: How to set SelectedValue of DropDownList in GridView
I'm trying to set the selected value of a DropDownList which sits inside the
The Dropdownlist data binding using throw common function. In this have a problem in
I have to bind an Html.DropDownList with just two items statically. Text=Yes Value=1 Text=No
I have a DropDownList in my aspx file like this: <asp:DropDownList runat=server ID=MaxRec> <asp:ListItem>10</asp:ListItem>
I'm having problem accessing the text field in a selected value of Html.DropdownList. My

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.