selectlist

MVC4 SelectList not selected default object

时间秒杀一切 提交于 2019-12-12 19:13:05
问题 My select list isn't selecting the default object being brought in through code. I first create my SelectList like so: public SelectList CreateSelectList(object objSelected = null) { return new SelectList(GetAll().OrderBy(s => s.NumericalValue), "PeriodID", "Name", objSelected); } My objSelected gets filled with a Guid that's associated with the PeriodID. Inside my controller I define my viewbag variable to the new select list. public ActionResult Edit(Guid id) { Classroom classroom =

Set Selected Item in SelectList Collection

喜夏-厌秋 提交于 2019-12-12 15:19:26
问题 I have a class with the following property. It constructs a SelectList object from an existing list, and then sets the selected item. public SelectList ProviderTypeList { get { SelectList list = new SelectList([...my collection...], "Value", "Key"); SelectListItem item = list.FirstOrDefault(sli => sli.Text == SelectedProviderType); if (item != null) item.Selected = true; return list; } } However, when this code is finished, item.Selected is true. But the corresponding item in the SelectList

Assigning select list values to array

无人久伴 提交于 2019-12-12 11:11:38
问题 I have an array initialised in script var listarray = new Array(); And have a dynamically created select list --- <select multiple size=6 width=150 style="width:150px" name="ToLB" > </select> My question is how to assign all values of select list to the array. Thanks in advance. 回答1: You can do this like : JQuery- var optionVal = new Array(); $('select option').each(function() { optionVal.push($(this).val()); }); Javascript- var x = document.getElementById("mySelect"); var optionVal = new

Angularjs checkbox checked by default on load and disables Select list when checked

心不动则不痛 提交于 2019-12-12 07:08:43
问题 noob on stack overflow here. I am working on a webpage that has a transfer job function. This lets the user check a check-box to send the job back to the office, or select a technician from a list of all that are available. My question is how to setup the check-box so that it is checked by default when the page loads and have the select list disabled accordingly. Here is the code that I have for it at the moment: <div ng-app=""> Send to Office: <input type="checkbox" ng-model="checked" ng

asp:DropDownList selectedvalues in multiple selection list

做~自己de王妃 提交于 2019-12-12 04:46:09
问题 I have asp:DropDownList wich is populated from SQLdatasource and I need to set selected items on select list (asp:DropDownList or asp:DropDownList). Here is my code: <asp:SqlDataSource runat="server" ID="sqlAihealueet" ConnectionString="Server=SQL2008;Database=Data;UID=123;PWD=123" SelectCommand="SELECT TOP (100) PERCENT valikkoaktiivinen, alue, id, otsikko, osa1b, osa2b, osa3b, osa4b FROM dbo.FiValikko"></asp:SqlDataSource> <asp:DropDownList name="aihevalinta" id="aihevalinta" multiple="true

Could not pass Dropdownlist Selected Value to Action Method

房东的猫 提交于 2019-12-11 20:12:04
问题 I have used a ModelView for static Dropdownlist values and tried to call print method from Razor in MVC4. However, I cannot pass the selected Dropdownlist value to teh Action method while I could pass the other parameters in input field. Could you please tell me where I made mistake? ApplicantViewModel: public class ApplicantViewModel { public IEnumerable<Applicant> Applicants { get; set; } //Codes for Dropdownlist values public string SelectedValue { get; set; } public IEnumerable

Set all values in SelectList in C#

本秂侑毒 提交于 2019-12-11 20:11:31
问题 In a SelectList object, I want that the Text property of each element of the SelectList should also be the value. For eg: SelectList s=new SelectList(some list); s.ElementAt(i).Value=s.ElementAt(i).Text; Is there any way to do this APART from using a loop? Is there any inbuilt method or something like that to accomplish this? 回答1: You can use the following Constructor overload for SelectList: public SelectList( IEnumerable items, string dataValueField, string dataTextField ) You can then,

WatIn Add a new option to a Selectlist?

对着背影说爱祢 提交于 2019-12-11 17:34:12
问题 I need to add a new option to a selectList in one of my unit tests, and I can't figure out how to do it. The Dropdown currently has 2 options, I want to add a third, and use it. I tried to use JavaScript injection using http://stevenharman.net/blog/archive/2007/07/10/add-option-elements-to-a-select-list-with-javascript.aspx as a base, but that failed. I get exceptions that crash the IE browser every time, and the text "RunScript failed" gets printed into my logs even though I don't use that

How to populate details fields on combo box selected item change in ASP.net MVC

喜你入骨 提交于 2019-12-11 16:44:01
问题 I have following controller class methods for get and post actions of updating a person record in my MVC application using a WCF service. There I'm using a combobox to select the ID. Here is my controller class methods for getting the person details. public ActionResult updatePerson() { Service1Client SCOBJ = new Service1Client(); List<Person> PeLi = SCOBJ.GetPersons().ToList(); ViewBag.List = PeLi.Select(x => new SelectListItem { Value = (Convert.ToString(x.Id)), Text = x.FName + " " + x

How to set different preconfigured default values for DropDownList in View using ASP.NET MVC?

ε祈祈猫儿з 提交于 2019-12-11 15:27:52
问题 I've created a program which has the ability to configure 2 keys to eachother, for example: Key 1 = key a, key 2 = key b, key 3 = key c, etc With the following configuration page: When pressing submit button it will send the configuration to the database: This works fine, but now I am trying to create a edit page for the configuration. In this configuration page I'm using the query that gets the configuration from the database and puts this in a WebGrid: Query: var v = (from a in dbProducts