奇怪了 为什么运行的时候明明会显示数据 怎么
DropDownList3.SelectedItem.Text
DropDownList3.SelectedValue
都为空 郁闷 请教大家
 Ajax.Utility.RegisterTypeForAjax(typeof(AjaxMethod));
        AjaxMethod dbobj = new AjaxMethod();
        if (!Page.IsPostBack)
        {
            this.DropDownList1.DataSource = dbobj.GetprovinceList();
            this.DropDownList1.DataTextField = "brtype";
            this.DropDownList1.DataValueField = "brtypeid";
            this.DropDownList1.DataBind();
            this.DropDownList1.Attributes.Add("onclick", "cityResult();");
            this.DropDownList2.Attributes.Add("onclick", "areaResult();");//触发areaResult()函数
     }

-----
function areaResult() { 
  var area=document.getElementById("DropDownList2");
  AjaxMethod.GetAreaList(area.value,get_area_Result_CallBack);//调用访问类GetAreaList方法
}
  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
}
-------
 [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
        public DataSet GetAreaList(int cityid)
        {
            string sql = "select * from tb_thirdclss where setypeid =" + cityid;
            sd = dbobj.Getdateset(sql);
            return sd;
        }
--运行没问题 能够实现联动和显示数据 为什么DropDownList3.SelectedItem.Text
DropDownList3.SelectedValue 得不到值呢?请教!......

解决方案 »

  1.   

    ajax没传视图所以值取不到用Request.Form["DropDownList3"]试试
      

  2.   

    你是js 给DropDownList3 赋值 在CS里是得不到的你把DropDownList3选择后把值保存到一个隐藏控件里 然后在CS 从隐藏空间里去取值
      

  3.   

    可能是跟你的AJAX方法有关系,在AJAX方法内的控件的值在方法外取不到.
      

  4.   

    <input type="Hidden" runat="server" id="HiddenValue" />
    然后到后台取HiddenValue的值
      

  5.   

    Request.Form["DropDownList3"] 这样是能够得到为什么我做还有一个可以Droprovince.SelectedValue.ToString()这样可以得到呢?想不明白鸟.....
      

  6.   

    用js给DropDownList赋值的话,状态没有保存,一回传就没有了。