当前位置: 代码迷 >> ASP.NET >> (小山)ajax 实现无刷新下拉联动(用在用户控件中就取的客户端取不到值)?解决办法
  详细解决方案

(小山)ajax 实现无刷新下拉联动(用在用户控件中就取的客户端取不到值)?解决办法

热度:4309   发布时间:2013-02-26 00:00:00.0
(小山)ajax 实现无刷新下拉联动(用在用户控件中就取的客户端取不到值)?
我用的方法是这个     Response.Write(Request.Form[ "DropDownList2 "]);

文件   :aa.ascx

cs     代码


Ajax.Utility.RegisterTypeForAjax(typeof(AjaxMethod));
if(!Page.IsPostBack)
{
this.DropDownList1.DataSource=AjaxMethod.GetPovinceList();
this.DropDownList1.DataTextField= "province ";
this.DropDownList1.DataValueField= "provinceID ";
this.DropDownList1.DataBind();

this.DropDownList1.Attributes.Add( "onclick ", "cityResult(); ");
this.DropDownList2.Attributes.Add( "onclick ", "areaResult(); ");
}

js代码

<SCRIPT   language= "javascript ">
//城市------------------------------
function   cityResult()  
{  
var   city=document.getElementById( "aa1_DropDownList1 ");
AjaxMethod.GetCityList(city.value,get_city_Result_CallBack);
}

function   get_city_Result_CallBack(response)
{
if   (response.value   !=   null)
{
//debugger;
document.all( "aa1_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].city;
       var   id=ds.Tables[0].Rows[i].cityID;
       document.all( "aa1_DropDownList2 ").options.add(new   Option(name,id));
     }
}
}
return
}
//市区----------------------------------------
function   areaResult()  
{  
var   area=document.getElementById( "aa1_DropDownList2 ");
AjaxMethod.GetAreaList(area.value,get_area_Result_CallBack);
}
function   get_area_Result_CallBack(response)
{
if   (response.value   !=   null)
{
document.all( "aa1_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].area;
       var   id=ds.Tables[0].Rows[i].areaID;
       document.all( "aa1_DropDownList3 ").options.add(new   Option(name,id));
     }
}
}
return
}
function   getData()
{
var   province=document.getElementById( "aa1_DropDownList1 ");
var   pindex   =   province.selectedIndex;
var   pValue   =   province.options[pindex].value;
var   pText     =   province.options[pindex].text;

var   city=document.getElementById( "aa1_DropDownList2 ");
var   cindex   =   city.selectedIndex;
var   cValue   =   city.options[cindex].value;
var   cText     =   city.options[cindex].text;

var   area=document.getElementById( "aa1_DropDownList3 ");
var   aindex   =   area.selectedIndex;
var   aValue   =   area.options[aindex].value;
  相关解决方案