省市级联

1.在VS中添加dome5,将已经下好的easyui复制过来,添加引用Newtonsoft.Json.dll
2.创建HtmlPage1.html

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="easyui/jquery.min.js"></script>
    <script src="easyui/jquery.easyui.min.js"></script>
    <link href="easyui/themes/icon.css" rel="stylesheet" />
    <link href="easyui/themes/default/easyui.css" rel="stylesheet" />
    <script src="easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        $(function () {
            var data = [{ id: 1, text: "夕颜" }, { id: 2, text: "暮颜",selected:true }, { id: 3, text: "朝颜" }]
            $("#com").combobox({
                editable: false,
                //数据列表加载。
                data: data,
                valueField: 'id',
                textField: 'text',
                               });
           
            $("#com1").combobox({
                editable: false,
                //通过URL加载远程列表数据
                url: 'WebProall.aspx',
                valueField: 'ProvinceId',
                textField: 'ProviceName',
                onLoadSuccess: function () {
                    //获取下拉列表绑定的所有数据
                    var a = $("#com1").combobox("getData");
                    //选中默认第一个
                    $("#com1").combobox("select",a[0].ProvinceId)
                },
                onSelect: function () {
                    var value = $("#com1").combobox("getValue");
                    $("#com2").combobox(
                        {
                            url: 'WebCity.aspx?ProvinceId=' + value,
                            valueField: 'CityId',
                            textField: 'CityName',
                            onLoadSuccess: function () {
                                var a = $("#com2").combobox("getData");
                                $("#com2").combobox("select", a[0].CityId)
                            }
                        }
                        );

                }
            });
            $("#com2").combobox({
                editable: false     
            });

        })
    </script>

body里的代码

  <input type="text" id="com" /><br />
      省:<input type="text" id="com1" />
      市:<input type="text" id="com2" />

3.添加ADO.NET实体数据模型(省略)
4.添加WebProall.aspx
aspx里面删掉多余代码,只剩下下面部分

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebProall.aspx.cs" Inherits="dome5.WebProall" %>

.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;

namespace dome5
{
    public partial class WebProall : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            using (CustomerSYSEntities db=new CustomerSYSEntities())
            {
                var pro = db.Province;
                string str = JsonConvert.SerializeObject(pro);
                Response.Write(str);
            }
        }
    }
}

5.同上添加WebCity.aspx
.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;

namespace dome5
{
    public partial class WebCity : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            using (CustomerSYSEntities db=new CustomerSYSEntities())
            {
                //var city = db.City;
                //string str = JsonConvert.SerializeObject(city);
                //Response.Write(str);
                int ProvinceId = int.Parse(Request["ProvinceId"]);
                using (CustomerSYSEntities d=new CustomerSYSEntities())
                {
                    var linq = from a in d.City
                               where a.ProviceId == ProvinceId
                               select a;
                    string str = JsonConvert.SerializeObject(linq);
                    Response.Write(str);
                }
               
            }
        }
    }
}

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值