Beruflich Dokumente
Kultur Dokumente
search
Questions
Tags
Users
Badges
Unanswered
Ask Question
1
1
Im working on a cascading drop-down and have used Method 1 in the following website: link text Everything is working correctly, I just wondered if it was possible to set the cascading drop-down to a value stored in a database? For example the list would be blank on a create page, but on an edit page the selected value would be set to a value in a database. I have updated the code below: CascadingDropDownList.js function bindDropDownList(e, targetDropDownList, selectedValue) { var key = this.value; var allOptions = targetDropDownList.allOptions; var option; var newOption; targetDropDownList.options.length = 0; for (var i = 0; i < allOptions.length; i++) { option = allOptions[i]; if (option.key == key) { newOption = new Option(option.text, option.value,selectedValue);
31460 87
cascadingdropdown
pdfcrowd.com
targetDropDownList.options.add(newOption); } } } JavascriptExtenstions.cs public static class JavaScriptExtensions { public static string CascadingDropDownList(this HtmlHelper helper, string name, string associatedDropDownList { var sb = new StringBuilder(); // render select tag sb.AppendFormat("<select name='{0}' id='{0}'></select>", name.Replace("'","")); sb.AppendLine();
// render data array sb.AppendLine("<script type='text/javascript'>"); var data = (CascadingSelectList)helper.ViewDataContainer.ViewData[name.Replace("'","")]; Linked var listItems = data.GetListItems(); How do I display selected value in a var colArray = new List<string>(); cascading drop down list? foreach (var item in listItems) colArray.Add(String.Format("{{key:'{0}',value:'{1}',text:'{2}'},selected:'{3}'}", item.Key, item.Value Related var jsArray = String.Join(",", colArray.ToArray()); ASP.NET MVC - Cascading Drop sb.AppendFormat("$get('{0}').allOptions=[{1}];", name.Replace("'",""), jsArray); Down sb.AppendLine(); How do I display selected value in a sb.AppendFormat("$addHandler($get('{0}'), 'change', Function.createCallback(bindDropDownList, $get('{1}'))); cascading drop down list? sb.AppendLine(); how will I call the on change event sb.AppendLine("</script>"); of the ajax dropdownlist? return sb.ToString(); } } public class CascadingSelectList { private IEnumerable _items;
trigger change event in cascading dropdown
JQuery: Cascading Drop Down List loses values when pressing back button Cascading drop down list in asp.net mvc 2.0?
New hot app: Facebook Albums To PDF
pdfcrowd.com
mvc 2.0? validating cascading dropdownlist AJAX, PHP, XML, and cascading drop-down lists C# ASP.NET AJAX CascadingDropDown Selected value property problem
cascadingdropdown
public CascadingSelectList(IEnumerable items, string dataKeyField, string dataValueField, string dataTextField edited Apr 6 '09 at 7:54 asked Apr 2 '09 at 10:45 how to display selected value in { drop down list in asp.net mvc? Roslyn _items = items; 158 1 4 15 Problem with cascading drop down _dataKeyField = dataKeyField; in asp.net 69% accept rate _dataValueField = dataValueField; Cakephp: cascading select boxes in _dataTextField = dataTextField.Replace("'",""); a view feedback _dataSelected = dataSelected; asp.net mvc - cascading dropdown }
link | improve this question
- one single table
public 2 Answers {
List<CascadingListItem> GetListItems()
active
oldest
votes
How to use a Cascading var listItems = new List<CascadingListItem>(); dropdownlist with Globalization of You'll need to modify the extension method to include a selected value like the normal dropdown. foreach (var item in _items) Views in MVC3 { You'll also need to modify the javascript: jquery cascading drop down var key = DataBinder.GetPropertyValue(item, _dataKeyField).ToString(); problem var value = DataBinder.GetPropertyValue(item, to add extra parameter here. _dataValueField).ToString(); function bindDropDownList(e, targetDropDownList) // Need how to assign existing value to var text = DataBinder.GetPropertyValue(item, _dataTextField).ToString().Replace("'",""); { cascading dropdownlist? var key var selected = DataBinder.GetPropertyValue(item, _dataSelected).ToString(); Dropdown lists bound = this.value; MVC listItems.Add(new CascadingListItem(key, var allOptions = targetDropDownList.allOptions; value, text.Replace("'",""),selected)); on the value of another depending dropdown list } var option; return listItems; var newOption; MVC 3 Cascading DropDownLists } targetDropDownList.options.length = 0; Cascading dropdown - How to } temporarily disable change event on dropdown to manipulate the for (var i=0; i < allOptions.length; i++) options public class CascadingListItem { How to return the appropriate { option = allOptions[i]; public CascadingListItem(string key, string value, string text, string selected) results with JSON in order to if (option.key == key) populate cascading drop down { { lists? this.Key = key; new Option(option.text, option.value); // Need to set to selected here newOption = how can one create a master detail this.Value = value; targetDropDownList.options.add(newOption); cascading dropdowns with json and this.Text = text.Replace("'",""); knockoutjs? }
Are you a developer? Try out the HTML to PDF API New hot app: Facebook Albums To PDF
pdfcrowd.com
} } } You'll need to pass in the extra parameter to the javascript function here:
Cascading Drop Down Lists with Lambda Expression in LINQ Cascaded Comboboxes and Entity Structure Cascading dropdowns in ASP.NET
Thanks. I have tried to follow your answer above and updated the question with code. Is this correct? I'm just learning ASP.NET MVC and JavaScript. Roslyn Apr 2 '09 at 12:41 Sorry I don't think you need to change this part: sb.AppendFormat("$addHandler($get('{0}'), ... Maybe try adding a selected option to the options: {{key:'{0}',value:'{1}',text:'{2}', selected:'{3}}} Jonathan Parker Apr 2 '09 at 22:20 Thanks. I have added in the above code as well as adding to CascadingSelectList and CascadingListItem. I get the following error:DataBinding: does not contain a property with the name? Roslyn Apr 3 '09 at 8:05 Please update your code in the question as I'm not sure exactly what you've done. Jonathan Parker Apr 4 '09 at 11:15 Thanks. I have updated the code above. Roslyn Apr 6 '09 at 7:54
feedback
With the help of the following link. I was able to get the selected value of a cascading drop-down.
pdfcrowd.com
feedback
Your Answer
Name Email
or
log in
Home Page
pdfcrowd.com
Not the answer you're looking for? Browse other questions tagged asp.net-mvc
cascadingdropdown or ask your own question.
question feed
about | faq | blog | chat | data | podcast | shop | legal | advertising info | mobile | contact us | feedback
stackoverflow.com api/apps careers serverfault.com superuser.com meta area 51 webapps gaming ubuntu webmasters cooking game development math photography stats tex english theoretical cs programmers unix apple wordpress physics home improvement gis electronics android security bicycles dba drupal sharepoint scifi & fantasy user experience
site design / logo 2012 stack exchange inc; user contributions licensed under cc-wiki with attribution required
rev 2012.2.21.1157
pdfcrowd.com