另一个下拉列表中的下拉列表项 [英] Dropdown list items on another dropdown
问题描述
HI
我的表单中有一个单选按钮(rbn1)和3个下拉列表(国家,州,城市).
如果我选择我的单选按钮,则应启用* country下拉列表,而应该禁用state和city下拉列表,country下拉列表项(印度,美国)
现在,如果我从列表项中选择印度",那么应该启用状态下拉列表"
和城市下拉菜单应禁用
现在,如果我从列表项中选择"USA",则应启用城市"下拉列表,而应禁用州"下拉列表.
HI
I am having a radio button(rbn1) and 3 drop down lists(country,state,city) in my form.
if i select my radio button then *country drop down should be enabled and state and city drop down should be disabled the country drop down list items ( India,USA)
Now if i select the India from list item..then state Drop down list should be enabled
and city drop down should be disabled
Now if i select the USA from list item then city Drop down list should be enabled and state drop down should be disabled.
Is it possible?
推荐答案
它称为 Cascading Dropdown .
看这里:
CascadingDropDown演示 [使用SQL数据库的AJAX级联下拉示例 [ ^ ]
在选择ASP.NET上填充级联DropDownList [面向初学者的AJAX(第2部分)-使用XMLHttpRequest和jQuery AJAX实施级联下拉列表 [ ^ ]
It''s called Cascading Dropdown.
Look here:
CascadingDropDown Demonstration[^]
AJAX Cascading Dropdown Example using SQL Database[^]
Populate Cascading DropDownList On Selection ASP.NET[^]
If not update panels, then you need to use traditional AJAX - XMLHttpRequest.
Refer:
AJAX for beginners (Part 2) - Using XMLHttpRequest and jQuery AJAX to implement a cascading dropdown[^]
可以直接通过ASP.NET完成,下面是代码.
This can be done directly through ASP.NET, Below is Code.
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
ddlState.DataSource = res.States(Convert.ToInt16(ddlCountry.SelectedValue));
ddlState.DataTextField = "StateName";
ddlState.DataValueField = "StateID";
ddlState.DataBind();
ddlState.Items.Insert(0, "Select");
ddlDist.Enabled = false;
ddlCity.Enabled = false;
}
protected void ddlState_SelectedIndexChanged(object sender, EventArgs e)
{
ddlDist.DataSource = res.Districts(Convert.ToInt16(ddlState.SelectedValue));
ddlDist.DataTextField = "DistName";
ddlDist.DataValueField = "DistID";
ddlDist.DataBind();
ddlDist.Items.Insert(0, "Select");
ddlDist.Enabled = true;
ddlCity.Enabled = false;
}
protected void ddlDist_SelectedIndexChanged(object sender, EventArgs e)
{
ddlCity.DataSource = res.Cities(Convert.ToInt16(ddlDist.SelectedValue));
ddlCity.DataTextField = "CityName";
ddlCity.DataValueField = "CityID";
ddlCity.DataBind();
ddlCity.Items.Insert(0, "Select");
ddlCity.Enabled = true;
}
此代码的完整概念在此处发布.
http://blog.johnbhatt.com/2012/08/dropdownlist-country- state-district-city.html
您可以使用UpdatePanel从PostBack保存页面.
Full concept of this code is posted here.
http://blog.johnbhatt.com/2012/08/dropdownlist-country-state-district-city.html
you can use UpdatePanel to save page from PostBack.
看看: ^ ]
..和更多类似线程在 CP搜索 [ ^ ]
Have a look: c# combobox selectedindexchanged events[^]
..and more similar threads on CP Search[^]
这篇关于另一个下拉列表中的下拉列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!