城市/区域 二级联动下拉菜单

来源:互联网 发布:json使用实例 编辑:程序博客网 时间:2024/04/29 14:35

 js 代码

function GetAreaList(res1,res2)
     {
         var CityID = res1.options[res1.selectedIndex].value;
         res2.length=0;
         var ds = Property_Default.GetArea(CityID).value;
         if(ds != null&& typeof(ds) == "object" && ds.Tables != null)
         {
            if(res1.selectedIndex != 0)
            {                
                for(var i=1; i<ds.Tables[0].Rows.length; i++)
                {
                    var name=ds.Tables[0].Rows[i].AreaName;
                    var id=ds.Tables[0].Rows[i].AreaID;
                    res2.options.add(new Option(name,id));
                }
            }
            else
            {
                res2.options.add(new Option("选择区域","0"));
            }
        }
     }

cs 代码

[AjaxPro.AjaxMethod]//获得区域数据
    public DataSet GetArea(int CityID)
    {
        string str = "select * from ktv_Area where CityID=" +  CityID;
        DataSet ds = DataBase.ExeSqlda(str);
        return ds;
    }

private DataSet GetData()
    {
        string str = "select * from property_City";
        DataSet ds = DataBase.ExeSqlda(str);
        return ds;
    }