根据其他下拉菜单中的选定项目填充下拉菜单,而无需发布页面 [英] Populate dropdown based on another dropdown selected item without posting the page

查看:77
本文介绍了根据其他下拉菜单中的选定项目填充下拉菜单,而无需发布页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含国家/地区名称的下拉列表,我想根据所选国家/地区填充另一个下拉列表,例如,如果我在第一个ddl中选择了一个州,则希望第二个下拉列表中都包含该州的城市我在第一个下拉列表中选择.还请考虑是否有机会在不发布页面的情况下获得该方​​案.

I have a dropdownlist which contains country names, i want to populate another dropdownlist based upon the country i have selected.for example if i select a state in first ddl i want the second dropdownlist to be populated with the cities of the state i selected in the first dropdownlist.if anyone have the related scenario plz guide me. also consider if there is any chance to get the scenario without posting the page

推荐答案

您正在寻找的称为级联下拉列表,并且有许多可用的示例. br/>
你可以从这里开始
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx [ ^ ]
What you are looking for is called a Cascading Dropdown and there are numerous examples available.

You can start here
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx[^]


以下是基于国家/地区"列表中的更改来更改状态"下拉列表的示例代码:

Here is the sample code to change State dropdown list based on changes in Country list as:

private void cboCountry_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
   if (!(cboCountry.SelectedItem == null))
   {
      cboState.ItemsSource = _stateList.Where(q => q.Country.Contains(cboCountry.SelectedItem.ToString())).Select(p => p.State).Distinct().ToList();
      cboState.SelectedIndex = 0;
   }
}


这篇关于根据其他下拉菜单中的选定项目填充下拉菜单,而无需发布页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆