改章节个人在上海喝咖啡的时候突然想到的...之前就有想写几篇关于数据列表的文章,所以回家到之后就奋笔疾书的写出来发表了

 <script src="jquery-1.9.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $.ajax({
                type: "post",
                contentType: "application/json",
                url: "WebService1.asmx/GetProvince",
                data: "{}",
                success: function (result) {
                    var strprovince;
                    for (var i = 0; i < result.d.length; i++) {
                        strprovince += "<option value='" + result.d[i].provinceID + "'>";
                        strprovince += result.d[i].provincename;
                        strprovince += "</option>";
                    }
                    $("#province").append(strprovince);
                }
            })
            $("#province").change(function () {
                $("#city option:gt(0)").remove();
                $("#area option:gt(0)").remove();
                $.ajax({
                    type: "post",
                    contentType: "application/json",
                    url: "WebService1.asmx/GetCity",
                    data: "{provid:'" + $(this).val() + "'}",
                    success: function (result) {
                        var strcity;
                        for (var i = 0; i < result.d.length; i++) {
                            strcity += "<option value='" + result.d[i].cityID + "'>";
                            strcity += result.d[i].cityname;
                            strcity += "</option>";
                        }
                        $("#city").append(strcity);
                    }
                })
            })
            $("#city").change(function () {
                $("#area option:gt(0)").remove();
                $.ajax({
                    type: "post",
                    contentType: "application/json",
                    url: "WebService1.asmx/GetArea",
                    data: "{cityid:'" + $(this).val() + "'}",
                    success: function (result) {
                        var strarea;
                        for (var i = 0; i < result.d.length; i++) {
                            strarea += "<option value='" + result.d[i].areaID + "'>",
                            strarea += result.d[i].areaname,
                            strarea += "</option>"
                        }
                        $("#area").append(strarea);
                    }
                })
            })
        })
    </script>
</head>
<body>
    <select id="province">
        <option>----请选择省----</option>
    </select>
    <select id="city">
        <option>----请选择市----</option>
    </select>
    <select id="area">
        <option>----请选择县----</option>
    </select>
</body>

 

    *********************************WebService1.asmx页面***********************************

 [WebMethod]
        public List<fenye.Model.province> GetProvince()
        {
            fenye.BLL.province prov = new fenye.BLL.province();
            List<fenye.Model.province> provlist = prov.GetListModel();
            return provlist;
        }
        [WebMethod]
        public List<fenye.Model.city> GetCity(string provid)
        {
            fenye.BLL.city city = new fenye.BLL.city();
            List<fenye.Model.city> citylist = city.GetListcity("father='" + provid + "'");
            return citylist;
        }
        [WebMethod]
        public List<fenye.Model.area> GetArea(string cityid)
        {
            fenye.BLL.area area = new fenye.BLL.area();
            List<fenye.Model.area> arealist = area.GetListarea("father='" + cityid + "'");
            return arealist;
        }

 

    *********************************DAL province********************************************

    每日一道理
在每个人心中,都曾停留过那些值得怀念的人,也许还在,也许早已消逝,在茫茫人海中丢失,于是,那份怀念便得凄凉,因为模糊的记忆中只剩下一个“空壳”,没有什么,甚至连自己的心都装不下,时间把一切抹平,也把当日的泪水封锁,因为已经没有,怀念只是悲凉!

    /// <summary>
  /// 取得数据列表
  /// </summary>
  public DataSet GetList(string strWhere)
  {
   StringBuilder strSql=new StringBuilder();
   strSql.Append("select id,provinceID,provincename ");
   strSql.Append(" FROM province ");
   if(strWhere.Trim()!="")
   {
    strSql.Append(" where "+strWhere);
   }
   return DbHelperSQL.Query(strSql.ToString());
  }

 //获取数据列表
        public List<Model.province> GetListModel()
        {
            List<Model.province> listprov = new List<Model.province>();
            DataTable dt = GetList("").Tables[0];
            foreach (DataRow row in dt.Rows)
            {
                Model.province prov = new Model.province();
                prov.id = Convert.ToInt32(row["id"]);
                prov.provinceID = row["provinceID"].ToString();
                prov.provincename = row["provincename"].ToString();
                listprov.Add(prov);
            }
            return listprov;
        }

    ***********************************DAL city*************************************************

    /// <summary>
  /// 取得数据列表
  /// </summary>
  public DataSet GetList(string strWhere)
  {
   StringBuilder strSql=new StringBuilder();
   strSql.Append("select id,cityID,cityname,father ");
   strSql.Append(" FROM city ");
   if(strWhere.Trim()!="")
   {
    strSql.Append(" where "+strWhere);
   }
   return DbHelperSQL.Query(strSql.ToString());
  }

 public List<Model.city> GetListcity(string strSql)
        {
            List<Model.city> listcity = new List<Model.city>();
            DataTable dt = GetList(strSql).Tables[0];
            foreach (DataRow row in dt.Rows)
            {
                Model.city city = new Model.city();
                city.cityID = row["cityID"].ToString();
                city.cityname = row["cityname"].ToString();
                listcity.Add(city);
            }
            return listcity;
        }

    *************************DAL area*************************************

    /// <summary>
  /// 取得数据列表
  /// </summary>
  public DataSet GetList(string strWhere)
  {
   StringBuilder strSql=new StringBuilder();
   strSql.Append("select id,areaID,areaname,father ");
   strSql.Append(" FROM area ");
   if(strWhere.Trim()!="")
   {
    strSql.Append(" where "+strWhere);
   }
   return DbHelperSQL.Query(strSql.ToString());
  }

 public List<Model.area> GetListarea(string sqlStr)
        {
            List<Model.area> listarea = new List<Model.area>();
            DataTable dt = GetList(sqlStr).Tables[0];
            foreach (DataRow row in dt.Rows)
            {
                Model.area area = new Model.area();
                area.areaID = row["areaID"].ToString();
                area.areaname = row["areaname"].ToString();
                listarea.Add(area);
            }
            return listarea;
        }

    ********************************BLL provice***************************************

    public List<Model.province> GetListModel()
        {
            return dal.GetListModel();
        }

    *********************************BLL city******************************************

    public List<Model.city> GetListcity(string sqlStr)
        {
            return dal.GetListcity(sqlStr);
        }

    *********************************BLL area********************************************

    public List<Model.area> GetListarea(string sqlStr)
        {
            return dal.GetListarea(sqlStr);
        }

文章结束给大家分享下程序员的一些笑话语录: 自从有了Photoshop,我再也不相信照片了!(没有Photoshop的年代,胶片照片年代做假的也不少,那时候都相信假的!)

--------------------------------- 原创文章 By 数据和列表 ---------------------------------