Dropdownlist 三级联动 无刷新的问题
脚本中
<script language="javascript">
//城市------------------------------
function cityResult()
{
var city=document.getElementById("DropDownList1");
Ajax_Method.GetCityList(city.value,CallbackCll);
}
function CallbackCll(response)
{
alert(response.value);
debugger;
document.all("DropDownList2").length=0;
var count = response.value.Rows.length;
alert(count);
if(count !=0)
{
for(var i=0; i<count; i++)
{
var name=response.value.Rows[i]["city_name"];
var id=response.value.Rows[i]["city_id"];
document.all("DropDownList2").options.add(new Option(name,id));
}
}
areaResult();
return
}
//市区----------------------------------------
function areaResult()
{
var area=document.getElementById("DropDownList2");
Ajax_Method.GetAreaList(area.value,CallbackCll);
}
function CallbackCll(response)
{
if (response.value != null)
{
document.all("DropDownList3").length=0;
var count = response.value.Rows.length;
if(count !=0)
{
for(var i=0; i<count; i++)
{
var name=response.value.Rows[i]["qx_name"];;
var id=response.value.Rows[i]["qx_id"];;
document.all("DropDownList3").options.add(new Option(name,id));
}
}
}
return
}
</script>
后台 代码中
public partial class Ajax_Method: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(Ajax_Method));
if (!IsPostBack)
{
this.DropDownList1.DataSource = GetProvinceList();
this.DropDownList1.DataTextField = "sf_name";
this.DropDownList1.DataValueField = "sf_id";
this.DropDownList1.DataBind();
this.DropDownList1.Attributes.Add("onchange", "cityResult();");
this.DropDownList2.Attributes.Add("onchange", "areaResult();");
}
}
public DataTable GetProvinceList()
{
string sql = "select * from ShengFen";
return Common.getsql(connectionstring_static, sql);
}
[AjaxPro.AjaxMethod]
public static DataTable GetCityList(int provinceid)
{
string sql = "select * from City where sf_id = " + provinceid;
DataTable dt=Common.getsql(connectionstring_static,sql);
return dt;
}
[AjaxPro.AjaxMethod]
public static DataTable GetAreaList(int cityid)
{
string sql = "select * from Qx where City_id = " + cityid;
DataTable dt=Common.getsql(connectionstring_static,sql);
return dt;
}
}
当加载页面的时候只显示 省份的名字 城市 和 区 没有显示 选择某个省份的时候 城市 和 区也不显示