大家看以下代码:假如我按下其他按钮提交给服务器 如何做到DropDownList2,DropDownList3选定项不改变,按我这样做的话结果按下其他按钮提交给服务器后的结果DropDownList2,DropDownList3都为空了,我应该如何修改,谢谢~! this.DropDownList1.DataSource = dbobj.GetprovinceList();
            this.DropDownList1.DataTextField = "brtype";
            this.DropDownList1.DataValueField = "brtypeid";
            this.DropDownList1.DataBind();
            this.DropDownList1.Attributes.Add("onchange", "cityResult();");
            this.DropDownList2.Attributes.Add("onchange", "areaResult();");
前台:
function cityResult() 

var city=document.getElementById("DropDownList1");
AjaxMethod.GetCityList(city.value,get_city_Result_CallBack);
}

function get_city_Result_CallBack(response)
{
if (response.value != null)
{
       document.all("DropDownList2").length=0; 
          
     var ds = response.value;
    
if(ds != null && typeof(ds) == "object" && ds.Tables != null)
{
for(var i=0; i<ds.Tables[0].Rows.length; i++)
     {
     var name=ds.Tables[0].Rows[i].setype;
       var id=ds.Tables[0].Rows[i].setypeid;
       document.all("DropDownList2").options.add(new Option(name,id));
     }
}
}
areaResult();
return
}
//企业三类----------------------------------------
function areaResult() 

var area=document.getElementById("DropDownList2");
AjaxMethod.GetAreaList(area.value,get_area_Result_CallBack);
}
function get_area_Result_CallBack(response)
{
if (response.value != null)
{
document.all("DropDownList3").length=0;    
     var ds = response.value;
    
if(ds != null && typeof(ds) == "object" && ds.Tables != null)
{
for(var i=0; i<ds.Tables[0].Rows.length; i++)
     {
       var name=ds.Tables[0].Rows[i].thtype;
       var id=ds.Tables[0].Rows[i].thtypeid;
       document.all("DropDownList3").options.add(new Option(name,id));
     }
}
}
return
}

解决方案 »

  1.   

    用AJAX把DropDownList放到updatepanel里
      

  2.   

    你这样做不知道 怎么保存,你可以给他们默认选项,如果response.value没有带值的,给下拉中添加个默认值就可以了
      

  3.   

    我曾经也试过用客户端回调的方法实现二级联动,是成功了,当我点击提交按钮的时候取得的值不是想要的结果,是因为点击按钮后回发了执行page_onlaod{}页面内容变了,我也没有成功解决呢,估计原因差不多吧
      

  4.   

    这正式许多“假的”asp.net coder毒害的结果。我一直主张写任何页面前都先设计好一个测试:拖一个Button到页面上,开发阶段运行时随时在正常操作流程中点这个Button测试状态是否保持了。如果这个测试不通过,请认定你的一点小麻烦将是会在增加交互流程是成倍放大,麻烦不断。
      

  5.   

    1楼直接回复了你的问题。我只是评论一二。ajax技术是不错的,但是如何使用要结合你的整体设计需求。许多脚本范例中的代码只是适应根本不需要保持状态的设计,当你想也不想就把它用在需要保持状态的地方,就会上当。
      

  6.   

    什么意思??没看懂你是什么意思.
    是你选中后的值被还原回初始值了吗?postback了?把你绑定下拉框的放到!IsPostBack中去