dropdownlist for following

var dropdown = (from role in db.aspnet_Users where role.aspnet_Roles.Any(a => a.RoleName == "supervisor") select new { text = role.UserName, value = role.UserId }).ToList();

code to generate dropdown list having dropdown.text as DropdownList item/text
and dropdown.value as DropdownList value
This code Present in my view.cshtml

-------------Problems Reply------------

using razor:

new SelectList( dropdown ,
"text" ) )

where dropdown is your variable

Also considering moving your code to the controller and passing the variable through viewbag (ie: ViewBag.dropdownitems = dropdown)

Category:asp.net mvc 3 Views:0 Time:2011-11-25

Related post

  • asp:DropDownList Error: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items 2008-09-01

    I have a asp.net 2.0 web site with numerous asp:DropDownList controls. The DropDownList control contains the standard info city, state, county etc... info. In addition to the standard codes the site also has custom codes that the users can configure

  • DropdownList autoposback after client confirmation 2008-09-16

    I have a dropdownlist with the autopostback set to true. I want the user to confirm if they really want to change the value, which on post back fires a server side event (selectedindexchanged). I have tried adding an onchange attribute "return confir

  • How to use javascript with an asp.net dropdownlist control? 2008-09-23

    I don't currently use ajax.net though I would be open to it if it is the only solution. I have a auto-complete control on screen that I am using to populate a asp.net dropdownlist with values through javascript (jQuery). I have had to use EnableEvent

  • Dropdownlist control with s for asp.net (webforms)? 2008-09-24

    Can anyone recommend a dropdownlist control for asp.net (3.5) that can render option groups? Thanks --------------Solutions------------- I've used the standard control in the past, and just added a simple ControlAdapter for it that would override the

  • Bind ASP.NET DropDownList DataTextField to method? 2008-09-25

    Is there anyway to have items in an ASP.NET DropDownList have either their Text or Value bound to a method on the source rather than a property? --------------Solutions------------- The only way to do it is to handle the Databinding event of the Drop

  • Hide triangle of dropdownlist when using css with media print 2008-10-02

    I'm using @media print in my external css file to hide menus etc. However while printing the little triangle of a dropdownlist still shows. Is there a css setting available to hide it as well and only print the selected item? --------------Solutions-

  • How do you bind a DropDownList in a GridView in the EditItemTemplate Field? 2008-10-05

    Here's my code in a gridview that is bound at runtime: ... <asp:templatefield> <edititemtemplate> <asp:dropdownlist runat="server" id="ddgvOpp" /> </edititemtemplate> <itemtemplate> <%# Eval("opponent.name") %>

  • DropDownList in Repeater control, can't fire SelectedIndexChanged 2008-10-06

    I have a repeater control where in the footer I have a DropDownList. In my code-behind I have: protected void ddMyRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItem

  • Don't display HTML code and entities in dropdownlists 2008-10-07

    When I add &nbsp; or &eacute; to a text value of a listitem, it display the code of the HTML entity instead of the result (a space or é). I can add "physical" non-breaking spaces or special chars, but I would like to avoid that if possible. S

  • When does a DropDownList retain the value from postback at the SelectedIndexChanged Event Handler 2008-10-07

    To Clarify to all this problem absolutely does not stem from rebinding of the controls and the value does not remain the initial value after binding. I have a DropDownList on an aspx page which is being used in multiple projects. Along the life cycle

  • FormField DropDownList height 2008-10-09

    I want to know how to set the height property for the HTML <select> in code. I tried setting .Attribute.Add("Style","Height:120px") just to see if I could get it to change but to no avail. --------------Solutions------------- Better yet, give i

  • asp.net : Getting SelectedItem of a DropDownList and retaining list items 2008-10-13

    Here's the issue.. I have small page which has label, dropdownlist and a submit button. <div> <asp:label id="Message" runat="server"/> <br /> Which city do you wish to look at on hotels for?<br /><br /> <asp:dropdownl

  • Dynamically bind data to dropdownlist in asp.net mvc 2008-10-18

    How to dynamically bind data to <%Html.Dropdownlist.... in ASP.NET MVC? --------------Solutions------------- Just pass the correct IEnumerable as the typed model or ViewData. Try something like this (out of my head): <%= Html.DropDownList(strin

  • Sorting a DropDownList? - C#, ASP.NET 2008-10-21

    I'm curious as to the best route (more looking towards simplicity, not speed or efficiency) to sort a DropDownList in C#/ASP.NET - I've looked at a few recommendations but they aren't clicking well with me. Edit: Folks, I do not have control over how

  • How can I get an UpdatePanel to intercept a CompositeControl's DropDownList 2008-10-22

    I have a CompositeControl that contains a DropDownList. I have set the AutoPostBack property of the DropDownList to true. On the page, I have: <asp:UpdatePanel ID="UpdatePanel" runat="server"> <ContentTemplate> <MyControl:Control ID="C

  • ASP.NET Dropdownlist selectedindexchanged event not firing on up / down arrow 2008-10-26

    I have a server dropdownlist in an Ajax updatepanel. When I use the mouse to click on an item it fires the postback but when I click the up/down arrow to change entries, this is not firing. What could be reason? --------------Solutions------------- T

  • Alternative UI control for large data lists instead of DropDownList 2008-10-29

    I am using C# and ASP.NET with version 2.0 of the .NET Framework library on this particular project. We are also using the AjaxControlToolkit. The AjaxControlToolkit should have the controls available to make a descent User Interface solution to the

  • C# - Dumping a list to a dropdownlist 2008-10-29

    List<String> nameList = new List<String>(); DropDownList ddl = new DropDownList(); List is populated here, then sorted: nameList.Sort(); Now I need to drop it into the dropdownlist, which is where I'm having issues (using foreach): foreac

  • Implementing an editable DropDownList in ASP.NET 2008-10-30

    What's the most elegant way of implementing a DropDownList in ASP.NET that is editable without using 3rd party components. As a last resort I will probably try using a TextBox with an AutoCompleteExtender with an image to 'drop down' the list; or a T

  • Asp.net - Add blank item at top of dropdownlist 2008-11-05

    Why is the dropdown not showing my blank item first? Here is what I have drpList.Items.Add(New ListItem("", "")) With drpList .DataSource = myController.GetList(userid) .DataTextField = "Name" .DataValueField = "ID" .DataBind() End With Edit ~ I am b

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.118 (s). 11 q(s)