四级联动的怪问题?
做了个四级联动,可是只有三级能联动,如第一级改变,第二,三级会自动改变,第四级不会变.但是,如果手动改变第二级,则三,四级能自动改变.具体做法简述:一二三级都设置成AutoPostBack=true;第一二三级的SelectedIndexChanged事件中都把下一级下拉框重新绑定一下.
------解决方案--------------------你还是 用SQL语句 看看查询出来了吗?
说的是四级。
------解决方案--------------------可能和页面刷新有关
------解决方案--------------------我这个可行,写在一起了,没用code-behind,直接复制过去就能运行了,没数据库支持
<%@ Page Language= "C# " %>
<%@ Register Assembly= "MagicAjax " Namespace= "MagicAjax.UI.Controls " TagPrefix= "ajax " %>
<%@ Import Namespace= "System.Data " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<script runat= "server ">
void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
// Load default Provinces and Cities.
LoadProvinceData();
LoadCityData();
LoadDistrictData();
}
}
#region event handler(s)
void drpCountry_SelectedIndexChanged(object sender, EventArgs e)
{
LoadProvinceData();
LoadCityData();
LoadDistrictData();
}
void drpProvince_SelectedIndexChanged(object sender, EventArgs e)
{
LoadCityData();
LoadDistrictData();
}
void drpCity_SelectedIndexChanged(object sender, EventArgs e)
{
LoadDistrictData();
}
#endregion
#region private helpers
void LoadProvinceData()
{
DataTable dtProvince = new DataTable();// null;
// In this demo, we just provider provinces for Chinese
if (drpCountry.SelectedValue.ToLower() == "cn ") {
// In your case, maybe you like to populate the Province data
// from the back-end datastore such as database.
dtProvince = CreateProvinceTable();
}
drpProvince.DataSource = dtProvince;
drpProvince.DataBind();
}
void LoadCityData()
{
// In your case, maybe you perform the search in your database
// by ADO.NET with inner-sql or stored procedure.
DataTable dtCity = CreateCityTable();
DataView dvCity = dtCity.DefaultView;
// Providers a dummy ProvincId when there are none of provinces to select.
string selectedProvinceId = (drpProvince.SelectedValue.Length != 0) ? drpProvince.SelectedValue : "-1 ";
dvCity.RowFilter = "ProvinceID= " + selectedProvinceId;
drpCity.DataSource = dvCity;
drpCity.DataBind();
}
void LoadDistrictData()
{
// Clears the items
drpDistrict.Items.Clear();
// In this demo, we just only provider districts for Chongqing city.
if (drpCity.SelectedValue != "5 ") return;
//
ListItem item = null;
//
item = new ListItem( "Shapingba ", "1 ");
drpDistrict.Items.Add(item);
//
item = new ListItem();
item.Text = "Yuzhongqu ";
item.Value = "2 ";
item.Selected =