关于DropDownList无刷新联动的问题

我是用AjaxPro2.0的,它是一个dll文件,引入到项目中,
例如一个省市 二级联动的例子:
在页面PageLoad时,注册一个
AjaxPro.Utility.RegisterTypeForAjax(typeof(命名空间.类名), this);

在后代写一个获取二级项内容的方法,可以传入参数,并直接返回一个结果集
[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.Read)]
public DataSet GetCity(object p_id)
{
    //p_id为省id
    DataSet ds = AreaLogic.GetCityByProvince(p_id.ToString());
    return ds;
}

在页面编写相应的JavaScript
function GetCitys()
{
  //ddlP是省的下拉框的编号
  var pro =document.getElementById("ddlP");
  //GetCity就是后台注册的方法明,GetCitys_CallBack是回调函数名
  命名空间.类名.GetCity(pro.value, GetCitys_CallBack);
 
}
function GetCitys_CallBack(response)
{
  if (response.value != null)
  {                   
      var ds = response.value;//获取结果集
      var ddlc=document.getElementById("ddlC");//找到市的下拉框
      ddlc.length=0;//清空市的下拉框里的内容
      ddlc.options.add(new Option("","-1"));//添加一个空项
      if(ds != null && typeof(ds) == "object" && ds.Tables != null)
      {
          //循环添加内容
          for(var i=0; i <ds.Tables[0].Rows.length; i++)
          {
            var text=ds.Tables[0].Rows[i].TITLE;
            var val=ds.Tables[0].Rows[i].AREA_ID;
            ddlc.options.add(new Option(text,val));
          }
      }
  }
}

 

最后还要在web.config 文件内添加一段代码
<system.web>
  <httpHandlers>
      <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/>   
  </httpHandlers>
</system.web>

posted @ 2008-08-06 22:24  天秤水  阅读(372)  评论(0编辑  收藏  举报